question

dylan2malec avatar image
dylan2malec asked

Modifying Objects in JSON turns values into Bools

Step 1: (Put in JSON Data)

5559-image.png

Step 2: (Hit the Save Button) 5566-image.png

I can only upload 2 attachments, so couldnt provide additional sample pictures.

Step 1: (Put Quotations "" around each number) Step 2: (Hit Save) (The quotations dissappeared on save and numbers were shown)

Step 1: (After previous steps with successful save, Modify JSON to set value of 19 to 191 Step 2: (Hit Save) This resulted in a broken state like the first 2 pictues

apis
image.png (31.8 KiB)
image.png (34.9 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

If you want to pair the string against the array, the JSON data format is incorrect, it should be: {"test": [1,2,3]}.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dylan2malec avatar image dylan2malec commented ·

That appears to be the case here. However looking online and using json validators it appears that it is still valid to start with arrays. Is there a specific reason why starting with arrays is not allowed? Or specifically in this instance?

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha dylan2malec commented ·

The JSON data format you wrote is not to pair a string against an array but an array with different types of data in it. If you just want to store different types of data into an array in Json data, you may need to put numerical data in quotes, like this: ["Test",["1","2","3"]].

0 Likes 0 ·
diyan avatar image diyan Xiao Zha commented ·

It's perfectly valid to have a JSON array of objects. The same bug happens to me. It occurs only in the Objects tab. It doesn't occur in Player Data or in Title Data.

If the outer element is a JSON Array, all the numeric values are converted to booleans.

For example, I need to store an array of objects with numeric properties. My object looks like this:

 {"val1":0,"val2":1}

This is a valid JSON array with 2 of such objects. This is what I put in the field:

 [{"val1":0,"val2":1}, {"val1":3,"val2":0}]

After saving and reloading the page, it turns into:

 [{"val1":false,"val2":true}, {"val1":true,"val2":false}]

This is wrong! A JSON array of objects is valid data! It must not alter it in this way. It's valid to have numeric values without quotes. Even worse. If I store just an array of numbers:

 [0,1,2,3,4,5]

After saving it becomes:

 [false, true, true, true, true, true]

This bug occurs only in the pages with Objects data - user objects and Content/Title Objects. It happens not only if I set the data from the game manager, but also from cloud script using the entity.SetObjects api.

1 Like 1 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.