-
Notifications
You must be signed in to change notification settings - Fork 180
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
Enable single-line declarations #47
Comments
I'd love to see this too, since this is how a human would write a JSON file to be readable. For example, I often work with GeoJSON and TopoJSON formats, and pretty-printing them looks like this: [
[
[
0
]
],
[
[
1390,
228
],
[
1770,
1181,
-119,
-960,
-549
],
[
3,
1104
],
[
1084
],
[
1086,
545
]
... To do this programmatically, I run a array/object regexp on the pretty-printed output, strip all returns and see if the resulting line is less than a threshold (say 80), and return the stripped version instead of the full one if so. |
Hi, any news about this feature? It could be very useful for me. Thanks |
…ot reaching more than 120chars in a line
can you please try adding this
into your user settings file and try formatting and let me know what you think it works only for arrays |
@dzhibas looks great, thanks for looking into this! The next step would be to handle nested arrays, e.g. stuff like this: {
"geometry": [
[
[3415, -64],
[3323, -15],
[3300, -64],
[3415, -64]
]
], |
…ot reaching more than 120chars in a line
I am also in favor of this feature. And I have come up with an idea to solve nested ones. function pretty(JsonObject A){
if(A.length>max_length_minify){
A.a = pretty(A.a);
A.b = pretty(A.b);
A.c = pretty(A.c);
/* other first level nested objects*/
// format first level of A, with formatted A.a, A.b, A.c ...
format(A, level=1, [A.a, A.b, A.c]);
}
return minify(A);
}
// where format(A) refer to its format JSON, and minify(A) refer to its minify JSON.
// Also max_length_minify is a parameter like max_arrays_line_length,
// and can be changed by user in configuration file I have never programmed in Python yet so I do not know if this approach match our case. |
Believe this will now be possible in #111 with the following settings
|
Investigating
|
I'm not sure this is a feature you'd want to support (should of course be configurable), but I'll raise it.
I'm in the process of writing a large json-schema file, now almost a 1000 line long and it will grow even more.
I'd want to have the ability to have one-liners where possible.
For example, instead of having this:
I'd hope to see this:
I have plenty one-liner objects (mostly json references) and it would really compress the json and make it more readable (in my opinion at least).
I would love to see a similar option for arrays of primitives, though that's less important.
This means that this:
would become this:
I understand that this may be an issue even with primitives as string values (and numbers for that matter) can end up having pretty long values.
The text was updated successfully, but these errors were encountered: