Checking whether a JSON formatter sorts property names
The formatter lays out object properties in the order they were written. This worksheet uses a z before a and a "10" before a "2" to confirm that nothing is sorted along the way.
Formatting and sorting are different jobs
Formatting changes whitespace: indentation, line breaks and the spaces after colons. Sorting changes the sequence of the properties themselves. A formatter that also sorted would produce output that looks tidy and differs from its input in a way a reviewer cannot see from the layout alone. This one keeps the original token sequence, so the first property written is the first property returned. That behavior matters when you diff a formatted file against its source, when you want a stored document to stay readable by the people who wrote it, and when property order carries a meaning the writer chose on purpose. A person who lists id first and name second, followed by details, has built a reading order, and a sort would replace it with an alphabetical one that nobody chose.
Alphabetic names in source order
The first control is {"z":1,"a":2}. Alphabetically, a comes before z, so a sorting tool would return a first. The formatter returns {"z":1,"a":2} in compact form, with z still leading. The values travel with their names, 1 with z and 2 with a, so reordering could not change which value belongs to which property. What it would change is the order in which a person or a streaming program meets them. The worksheet therefore uses a pair whose natural alphabetic order is the opposite of the written order, which makes any sorting immediately visible. Try swapping the written order to a first and z second, and the output will follow it, which confirms that the formatter is reading your sequence and not applying a fixed one of its own.
Numeric-looking names
The second control is {"10":"ten","2":"two"}. In a numeric sort, 2 comes before 10, and in a plain text sort "10" comes before "2" because the character 1 precedes 2. The two orderings disagree, which makes this pair a good trap for any tool that reorders. The formatter returns the object with "10" first, exactly as written. Property names in JSON are always strings, so these are text keys that happen to look like numbers, and the formatter treats them as text in the position where you wrote them. Keys like these appear in real data, for example a map from year or from numeric identifier to a record, and a lookup table keyed by 10 and 2 is exactly the kind of document where an unexpected reorder would be noticed too late.
What the specification says about order
RFC 8259 describes an object as an unordered collection of name and value pairs. A receiving program is therefore not entitled to rely on order, and many programs do not. Still, in practice the written order exists in the text, and some software preserves it while other software does not. Programming languages differ here. JavaScript, as defined from ES2015 onward, lists integer-like keys in ascending numeric order before other keys when it enumerates an object, so parsing the second control with JSON.parse and printing it again would put "2" first. A text-based formatter avoids that effect.
Nested objects and arrays keep their order too
The same rule applies at every depth. Take {"b":{"z":1,"a":2},"a":[3,1]}. The formatter keeps b before a at the top level, z before a inside b, and 3 before 1 in the array. The array [3,1] is descending on purpose, so an accidental sort would be easy to catch. Array order is part of the data, since arrays are ordered by definition, and the formatter never touches it. With an indent of 2 the output spreads this across lines but the sequence of every name and element stays as written. This is useful for documents with long nested configuration, where reading order and reviewing order matter to the people maintaining them. The array [3,1] in particular would change meaning if it were sorted, since a list of steps, a path or a pair of coordinates all depend on the sequence.
When a sorted copy is what you need
Some workflows do need sorted properties: comparing two documents that came from different systems, generating a stable fingerprint, or checking a configuration into version control so that diffs stay small. That is a separate transformation with its own rules about which sort applies, whether it is case sensitive, and whether it reaches nested objects. Define the rule explicitly and apply it with a tool built for it. The JSON Canonicalization Scheme in RFC 8785 is one published example, which sorts names by their UTF-16 code units and prints values in a defined form.
Duplicate names and order
RFC 8259 says that names within an object should be unique, and warns that receivers behave unpredictably when they are not. With a duplicate such as {"a":1,"a":2}, some parsers keep the first value, some keep the last, and some report an error. Order can therefore decide which value survives, which is another reason to keep it intact while formatting. Avoid duplicates in documents you write, and watch for them after merging two sources, which is a common way for them to appear. If you receive one, treat it as a data-quality problem to resolve with the sender instead of relying on any one parser's habit.
Member order and receiving systems
The two controls show that this formatter does not alphabetize and does not reorder numeric-looking names. They do not establish that object-member order carries business meaning in the receiving system. Most consumers ignore it. If yours does not, document that dependency in the interface description, because other tools in the pipeline may not preserve order the way this one does.
Keeping diffs small in version control
Teams that store JSON in version control often care about order for a practical reason: a reformat that moves properties around makes every line in a diff look changed, which hides the real edit. Keeping the original order means that a formatting pass changes only whitespace, and a reviewer can see a single added property as a single added line. If a team does want sorted files, agree on it once, apply it to the whole repository in one commit, and add a check to catch unsorted additions later. Mixing sorted and unsorted files creates the same noisy diffs the sorting was meant to prevent.
Reproduce the checks
Alphabetic names in source order
Open the Json Validator Formatter and enter:
- JSON input
{"z":1,"a":2}- Indent
0
Expected output:
Valid
trueFormatted
{"z":1,"a":2}The formatter does not alphabetize the properties.
Numeric-looking names
Open the Json Validator Formatter and enter:
- JSON input
{"10":"ten","2":"two"}- Indent
0
Expected output:
Valid
trueFormatted
{"10":"ten","2":"two"}The original token order remains intact.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08