Open webron opened 10 years ago
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
can you please try adding this
"keep_arrays_single_line": true
into your user settings file and try formatting and let me know what you think
it works only for arrays [...]
and extremely experimental :)
@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]
]
],
I am also in favor of this feature. And I have come up with an idea to solve nested ones. In Pretty Json we have a minify JSON and a format JSON, so can we pretty a file like this:
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. And sorry for not able to help with a pull request. Thank you.
Believe this will now be possible in #111 with the following settings
"brace_newline": true
"bracket_newline": true
Investigating
"description": { "$ref": "http://json-schema.org/draft-04/schema#/properties/description" }
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.