My first JSON is:
JavaScript
x
{
"categoryId":"Painting",
"subCategoryId":"Residential",
"alternatives": [1,2,3,4,5],
"criterias":["price","quantity","yom","company"],
"answers":[["1000","12343","4543","","4645646"],["12","23","34","","45"],["2014","","2000","1990","2005"],["xyz","","Abc","jkl","mno"]]
}
This will come from a java URL, here I am using PHP, in PHP I am calling a java URL.
My Second JSON is:
JavaScript
{"criterias":"Location"}
I am generating this using JQuery. How can I include the second JSON into the first JSON criterias?
Advertisement
Answer
You need to convert your first JSON string to object and add a new property to it.
If it is Java, you can use Google’s Gson library
JavaScript
Gson gson = new Gson();
JsonObject jsonObj = gson.fromJson (jsonStr, JsonElement.class).getAsJsonObject();
jsonObj.add("criterias", "Location");
If it is JavaScript,
JavaScript
var jObj = JSON.parse(jsonString);
jObj.criterias = "Location"; //jObj.NewItem = "NewValue";