Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format: ability to provide custom property ordering. #16

Open
johnspurlock opened this issue Feb 10, 2019 · 3 comments
Open

Format: ability to provide custom property ordering. #16

johnspurlock opened this issue Feb 10, 2019 · 3 comments
Assignees
Labels
feature-request Request for new features or functionality
Milestone

Comments

@johnspurlock
Copy link
Contributor

It would be great if new object additions could be specified with a defined property ordering (in formatting options). Something like the insertion function that exists, but for total ordering of existing objects.

This way adding new objects could retain a canonical property ordering with a single call to modify, without having to piece together multiple modify removals and individual modify inserts.

Thanks!

@aeschli
Copy link
Contributor

aeschli commented Feb 11, 2019

So an insert would also make cause changes to other existing properties?

@johnspurlock
Copy link
Contributor Author

Ah no, easiest case is just a single insert, but an object insert. For example:

const inputJson = '{}';
const newObj: any = {};
newObj.b = 'second';
newObj.a = 'first';  // a may be added later, but want it to appear before b in the output
const edits = jsonc.modify(inputJson, ['foo'], newObj, { formattingOptions: {} });
const outputJson = jsonc.applyEdits(inputJson, edits);
// outputJson (sans indentation) is: { "foo": { "b": "second", "a", "first" } }

@aeschli
Copy link
Contributor

aeschli commented Feb 12, 2019

Oh, so this is about the order of the properties of the inserted object.

@aeschli aeschli added the feature-request Request for new features or functionality label Oct 14, 2019
@aeschli aeschli added this to the Backlog milestone Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

2 participants