prettier-plugin-sort-json-array
v0.0.2
Published
A Prettier plugin to sort JSON arrays of objects based on a specified key
Readme
prettier-plugin-sort-json-array
A Prettier plugin to sort JSON arrays of objects based on a specified key.
Installation
npm install --save-dev prettier-plugin-sort-json-arrayUsage
Add the plugin to your Prettier configuration:
.prettierrc.json:
{
"plugins": ["prettier-plugin-sort-json-array"],
"jsonArraySortKey": "<key>",
"jsonArraySortAscending": true
}Options:
jsonArraySortKey- The object key to sort by.jsonArraySortAscending- Sort direction (default:true)
Example:
Input:
[
{ "id": 3, "name": "Charlie" },
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
]Output with jsonArraySortKey: "id":
[
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" },
{ "id": 3, "name": "Charlie" }
]License
MIT
