Everytime I push an JSONObject onto an array, it adds quotation marks and backslashes.
I have turned off smart quotes.
For some reason it is wrapping the JSONObject with quotes, putting that into the array and then since it is detect two quotes instead of one, it escape the likely quote with a backslash.
Would be nice if someone could look at this pls,
Ben
JSON.kmmacros (6.1 KB)
JSON - push Object Onto a JSON Array.kmmacros (2.5 KB)
var json_object = km.getvariable("JSON Object");
json_array.push(json_object)
A JSON value is just a String.
if you want to the bind the name json_object
to an actual JavaScript Object, rather than just to a string which represents one, you need to parse the JSON.
JSON.parse() - JavaScript | MDN
Incidentally, I think the confusion is already expressed in your macro title and variable names.
You can't "push an object onto a JSON array"
A JSON array is not an array.
It's a string, in the JavaScript Object Notation format.
Similarly in your code:
[]
is not a "json array" (which would simply be a string representation of an array).
It's an actual JavaScript Array.
JSON is a serialization format – a string format.
The map is not the territory.
2 Likes