0
Fixed

JSON.Stringify drops values

Kris 7 months ago in Bugs and problems updated by Vladimir Ovchinnikov 5 months ago 4

Hi

I want to use JSON.Stringify for later data transmission to the panel.

My data is an object of nested arrays of objects. For problem description however, I will use simpler data as the result is the same:

var defs = ["One","Two"];

var testObj = {

Z1_1:[defs,defs],

Z1_2:[defs,defs],

Z2_1:[defs,defs]

};

var defs is a 'template' array with which I populate the object.

Then I Stringify it:

var TSTR = JSON.Stringify(testObj);

IR.Log("TSTR JSON String:");

IR.Log(TSTR);


Here is the problem - the output is:

TSTR JSON String:

{"Z1_1":[["One", "Two"], {}], "Z1_2":[{}, {}], "Z2_1":[{}, {}]}


Apparently JSON.Stringify drops out simmilar data in following arrays.

Accordingly, testing the same code in VS Code, the output is correct:

TSTR JSON String:

{"Z1_1":[["One","Two"],["One","Two"]],"Z1_2":[["One","Two"],["One","Two"]],"Z2_1":[["One","Two"],["One","Two"]]}

If I use different arrays declarations for each object property (i.e. defs1, defs2, defs3 etc.) the output will be correct. Unfortunately I cannot do that as the aim is to dynamically add more properties to testObj with the same template array,


Can you please advice on this - is there any workaround this? Is there something I am missing? Or is this a bug or limitation in iRidium?

I am looking forward to see the solution!

Thanks!

GOOD, I'M SATISFIED
Satisfaction mark by Kris 5 months ago
Under review

Hello.

Thank you for the information. The key must be a string, i.e. the code must look like this:

var defs = ['One','Two'];
var testObj = {
"Z1_1":[defs, defs],
"Z1_2":[defs, defs],
"Z2_1":[defs, defs]
};

However, we will check the operation of JSON.Stringify and report the result.

+1

Use this code:

var defs = ['One','Two'];
var testObj = {
"Z1_1":[defs, defs],
"Z1_2":[defs, defs],
"Z2_1":[defs, defs]
};
var TSTR = JSON.Stringify(testObj, true);
IR.Log("TSTR JSON String:");
IR.Log(TSTR);


The JSON.Stringify method uses recursive nesting protection, but it captures objects at the same level.

Hi,

That works perfect now.


Thank you!