class QuestionHelper {

  public static JSONObject fillTemplate(
      JSONObject questionJson, Map<String, JsonNode> parameters, String questionName)
      throws JSONException, IOException {
    JSONObject clonedQuestionJson = new JSONObject(questionJson.toString()); // deep copy

    JSONObject instanceJson = clonedQuestionJson.getJSONObject(BfConsts.PROP_INSTANCE);
    instanceJson.put(BfConsts.PROP_INSTANCE_NAME, questionName);
    String instanceDataStr = instanceJson.toString();
    InstanceData instanceData =
        BatfishObjectMapper.mapper()
            .readValue(instanceDataStr, new TypeReference<InstanceData>() {});
    Map<String, Variable> variables = instanceData.getVariables();

    Client.validateAndSet(parameters, variables);
    Client.checkVariableState(variables);

    JSONObject modifiedInstanceData =
        new JSONObject(BatfishObjectMapper.writePrettyString(instanceData));
    clonedQuestionJson.put(BfConsts.PROP_INSTANCE, modifiedInstanceData);

    return clonedQuestionJson;
  }

}