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

Enable single-line declarations #47

Open
webron opened this issue Oct 7, 2014 · 7 comments
Open

Enable single-line declarations #47

webron opened this issue Oct 7, 2014 · 7 comments
Assignees
Labels

Comments

@webron
Copy link

webron commented Oct 7, 2014

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:

"description": {
      "$ref": "http://json-schema.org/draft-04/schema#/properties/description"
}

I'd hope to see this:

"description": { "$ref": "http://json-schema.org/draft-04/schema#/properties/description" }

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:

"enum": [
        "csv",
        "ssv",
        "tsv",
        "pipes",
        "multi"
]

would become this:

"enum": [ "csv", "ssv", "tsv", "pipes", "multi" ]

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.

@dzhibas dzhibas self-assigned this Oct 21, 2014
@mourner
Copy link

mourner commented Dec 16, 2014

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.

@alexcarrega
Copy link

Hi, any news about this feature? It could be very useful for me.

Thanks

dzhibas pushed a commit that referenced this issue Jul 14, 2016
…ot reaching more than 120chars in a line
@dzhibas
Copy link
Owner

dzhibas commented Jul 14, 2016

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 :)

@mourner
Copy link

mourner commented Jul 14, 2016

@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]
      ]
    ],

dzhibas added a commit that referenced this issue Jul 20, 2016
@qimuxi1990
Copy link

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.

@TerminalFi
Copy link
Collaborator

TerminalFi commented Apr 16, 2020

Believe this will now be possible in #111 with the following settings

"brace_newline": true
"bracket_newline": true

@TerminalFi
Copy link
Collaborator

TerminalFi commented Apr 16, 2020

Investigating

"description": { "$ref": "http://json-schema.org/draft-04/schema#/properties/description" }

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

No branches or pull requests

6 participants