Not sure what the error is because I don't see any. If you expected the result to be identical to the pasted result, then you should know that JSONSetElement escapes some unescaped values when setting JSONString elements. One that will always be escaped is the escape sequence character (\). The resulting JSON will always be a correct string and JSONString values must always reproduce the same string as was input when using JSONGetElement.
@marke1415 I have a suspicion that you might be trying to achieve something that would happen if you were specifying a different data-type, e.g., instead of JSONString, using JSONArray.
JSONSetElement processes value dependent on type. JSONString stores a string but the JSON itself is also a string. The value must be processed so that a call to JSONGetElement for keyOrIndexOrPath outputs the same value as was input by the call to JSONSetElement.
Try seeing what you get when you call JSONGetElement for the JSON you copied and pasted in your original post. It should become very obvious why JSONSetElement processes value.
I'm not sure it is clear what you are trying to do. It looks like you have a syntax error in your first example:
JSONSetElement [$data; $$MyJSon, JSONString]
The JSONSetElement commands takes 4 parameters, using parentheses, and your example shows 3 in square brackets.
Here's the base usage of this function:
JSONSetElement ( json ; keyOrIndexOrPath ; value ; type )
That 1st json param is if you want to ADD the keyOrIndexOrPath/value key-value pair INTO some existing JSON.
Then, you say that you received an "alert message", but the images you included doesn't seem to actually include an error message, just a picture of some strings of info that look like nested JSON arrays.
Are you trying to take that 2-dimensional JSON array stored in $$MyJSon and put that INTO an existing JSON object stored in a variable named $data? That is definitely possible.
Here's an example. If the variable $startingJSON contains a simple JSON object like this:
{ "someKey1" : "someValue1" }
And, you want it to change so that there is a 2nd key inside named "data" that contains the nested JSON array you have stored in $$MyJSon, you would do this: