-2

I made a sorted dictionary to pass through json to a javascript, however, it seems whenever I throw it into a json.dumps() it changes its order into alphabetical by keys. It is critical that I keep it in a certain order or else it will not work. Is there a way to achieve this?

0

1 Answer 1

2

Objects in JSON are an unordered collection of key:value pairs (same as dictionaries in Python), so you should use a different data structure if the order is relevant.

A structure like this (in JSON) would work:

{ "columns" : [ "id", "name", "age"],
  "rows" : [[ "john", "John Doe", 42],
            [ "jane", "Jane Miller", 28]
    ]
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.