prettier-rm-duplicate-json-keys
v1.1.6
Published
A Prettier plugin that removes duplicate keys from JSON files
Maintainers
Readme
Prettier Plugin: Remove Duplicate JSON Keys
Modified based on prettier-plugin-sort-json. A Prettier plugin that removes duplicate keys from JSON files and provides flexible sorting options.
Features
- Removes duplicate keys from JSON files
- Supports various sorting algorithms for JSON keys
- Configurable recursive sorting
- Case-insensitive sorting options
- Numeric and lexical sorting options
Installation
npm install --save-dev prettier-rm-duplicate-json-keysUsage
Add the plugin to your Prettier configuration:
{
"plugins": ["prettier-rm-duplicate-json-keys"],
"jsonRecursiveSort": true,
"jsonSortOrder": "lexical"
}Configuration
Options
jsonRecursiveSort(boolean, default: false)- When true, sorts JSON files recursively, including any nested properties
jsonSortOrder(string, default: "lexical")- Specifies the sorting algorithm to use
- Available options:
lexical: Standard alphabetical sortingnumeric: Numeric prefix sortingcaseInsensitiveLexical: Case-insensitive alphabetical sortingcaseInsensitiveNumeric: Case-insensitive numeric prefix sortingreverseLexical: Reverse alphabetical sortingreverseNumeric: Reverse numeric prefix sortingcaseInsensitiveReverseLexical: Case-insensitive reverse alphabetical sortingcaseInsensitiveReverseNumeric: Case-insensitive reverse numeric prefix sortingnone: No sorting
Example
Input JSON:
{
"a": 1,
"b": 2,
"b": 3,
"c": {
"z": 1,
"y": 2,
"z": 3
}
}Output JSON (with jsonSortOrder: "lexical"):
{
"a": 1,
"b": 2,
"c": {
"y": 2,
"z": 1
}
}Development
# Install dependencies
npm install
# Build the project
npm run buildLicense
ISC
