• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

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