JSON object order?

SLotman

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jul 3, 2017
Messages
261
I'm trying to read a JSON here, and I kind of have it working using brl.json. But I hit a problem: object values are being sorted and I need them in the order they are in the JSON file.

Other than turning objects into arrays, is there any other way I can just 'disable' sorting?

For example, I have on JSON:
Code:
"portrait": {
                "skin": [124,60,61],
                "eyes": [0,0,0],
                "mouth": [0,0,0],
                "beard": [0,0,0],
                "nose": [50,7,21],
                "hair": [0,0,0]
            }

But this is returning as sorted, like beard - eyes - hair - mouth, etc. I need them in the exact order in the file, because they will be rendered that way (and the order may change as well, its not like nose will be always on top of beard, for example).
 
F###! It uses 'map' to store objects, so it sorts them automatically.

Guess I'll have to make it an array of objects :/
 
Last edited:
Yes. But why do you need them in a specific order? Then maybe JSON is the wrong format to store it in the first place?
 
This will be a bunch of images rendered on top of each other, to make a character portrait. So I have several 'eyes',' 'mouths', 'hairs', etc to be stacked on top of each other.

Rendering them in different order can achieve different looks - so that's why order is important.

But yeah, apparently making it an array of objects works. The JSON gets a little uglier, but it works :p
 
Nope. This 'solved' it:


Code:
"portrait": {[
                { "skin": [124,60,61] },
                { "eyes": [0,0,0] },
                { "mouth": [0,0,0] },
                { "beard": [0,0,0] },
                { "nose": [50,7,21] },
                { "hair": [0,0,0] }
            ]}

As I said, making it an array of objects will return the objects in order.
 
Back
Top Bottom