0
I need to create a json object from scratch where each key has several values/values example:
'{"name":["daniel","dias"],"morada":["joao","allen"]}'
For that I am executing this code several times, but the result is presented with numerical generated Keys:
facetaPush - key name
Response - array with desired values
valuesFacetas - save json object final
var json_string = "";
json_string +='{\"'+facetaPush+'\":[' ;
for (var i = 0; i < response.length-1; i++) {
json_string +='\"'+response[i]+'\",';
}
json_string +='\"'+response[response.length-1]+'\"]}';
var json_obj = JSON.parse( json_string );
valuesFacetas[facetaPush].push(json_obj);
alert("valores facetas: "+valuesFacetas[facetaPush][facetaPush]);
edited question
– Daniel Dias
What is the reason for mounting JSON to a string? What do you mean by "key is dynamic so create the object statically"? can you give an example?
– Sergio