0.0.1 • Published 4 years ago

prettier-plugin-sorted-json v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

prettier-plugin-sort-json

A plugin for Prettier that sorts JSON files by property name.

Requirements

This module requires an LTS Node version (v10.0.0+), and prettier v2.0.0+.

Install

Using npm:

npm install --save-dev prettier-plugin-sort-json

Using yarn:

yarn add --dev prettier-plugin-sort-json

Description

This plugin adds a JSON preprocessor that will sort JSON files containing a JSON object alphanumerically by key. JSON files containing Arrays or other non-Object values are skipped.

Currently we only perform a shallow sort. Nested objects are not sorted.

Object entries are sorted by key using Array.sort, according to each character's Unicode code point value.

Examples

Before:

{
    "z": null,
    "a": null,
    "b": null,
    "0": null,
    "exampleNestedObject": {
        "z": null,
        "a": null
    }
}

After:

{
    "0": null,
    "a": null,
    "b": null,
    "exampleNestedObject": {
        "z": null,
        "a": null
    },
    "z": null,
}
0.0.1

4 years ago