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

Allow more control over sorting #1

Open
mikemanger opened this issue May 9, 2022 · 2 comments
Open

Allow more control over sorting #1

mikemanger opened this issue May 9, 2022 · 2 comments

Comments

@mikemanger
Copy link

In our project we want to sort everything in a json file, apart from any fields sub-keys where having them in a set order makes sense contextually, even if it just to make it easier for the programmer to look at the file.

I'm not sure what the best way of specifying this would be but having sortKeys accept a depth parameter might be a simply way of giving a bit more control.

@prantlf
Copy link
Owner

prantlf commented May 9, 2022

Wouldn't a depth parameter rather give up the control from some level on? I think that I don't understand it. Would you have an example of such structure?

@mikemanger
Copy link
Author

Hi, thanks for the response (and the recent release 👍).

Sorry I didn't explain very well, here is an example used to generate a form:

{
	"someid": {
		"name": "abc",
		"fields": {
			"name": {
				"meta": "here",
				"order": 0
			},
			"email": {
				"meta": "here",
				"order": 1
			}
		}
	},
	"anotherid": {
		"name": "something",
		"fields": {
			"button-text-1": {
				"meta": "here",
				"order": 0
			},
			"button-url-1": {
				"meta": "here",
				"order": 1
			},
			"button-text-2": {
				"meta": "here",
				"order": 2
			},
			"button-url-2": {
				"meta": "here",
				"order": 3
			}
		}
	}
}

With sortKeys set to true this would become:

{
	"anotherid": {
		"fields": {
			"button-text-1": {
				"meta": "here",
				"order": 0
			},
			"button-text-2": {
				"meta": "here",
				"order": 2
			},
			"button-url-1": {
				"meta": "here",
				"order": 1
			},
			"button-url-2": {
				"meta": "here",
				"order": 3
			}
		},
		"name": "something"
	},
	"someid": {
		"fields": {
			"email": {
				"meta": "here",
				"order": 1
			},
			"name": {
				"meta": "here",
				"order": 0
			}
		},
		"name": "abc"
	}
}

The JSON is still valid/works but it is harder for a human to parse because the order key is ignored.

I was suggesting being able to pass an int (e.g. sortKeys: 1 or sortKeyDepth: 1) to only order the top level of the json file which is important if there are a lot of form objects in the file.. but I'm sure there are better ways to do this.

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

No branches or pull requests

2 participants