Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

sort json file by keys #391

Merged

Conversation

tlightsky
Copy link

@gilmarsquinelato gilmarsquinelato merged commit 094324f into gilmarsquinelato:development May 9, 2020
@gabrielrobert
Copy link

@tlightsky @gilmarsquinelato It looks like this PR is causing problems for nested content. You can reproduce the problem easily:

With this PR:

var data = { nested: { content: 'will be removed' } };
JSON.stringify(data, Object.keys(data).sort(), 2);

Result:

"{
  "nested": {}
}"

Before this PR:

var data = { nested: { content: 'will be removed' } };
JSON.stringify(data, null, 2);

Result:

"{
  "nested": {
    "content": "will be removed"
  }
}"

@tlightsky
Copy link
Author

true,
maybe we should switch to this:
https://www.npmjs.com/package/json-stable-stringify
from:
https://stackoverflow.com/a/16168003

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants