Sort Comparator Builder
Add sort keys, preview on sample or pasted JSON, copy a readable comparator plus a one-line toSorted() usage.
~~~
Sort keys
Property
Type
Direction
Nulls
String compare
Locale
Numeric collation
Preview data
Generated code
Gotchas: Default sort() compares strings — [1, 10, 2] stays lexicographic.
Subtraction (a - b) breaks on NaN and coerces strings.
sort() mutates the array; use toSorted(compare) for a new copy.
~~~
About this tool
Multi-key comparators get verbose fast. This builder handles nulls, localeCompare, and nested properties — then shows the sorted output live.
~~~