Skip to content

Add ability to produce minified JSON (and perhaps YAML) output by typst query #4157

Closed

Description

@Andrew15-5

Description

I want to be able to write typst query --field value --minified file.typ metadata and get:

[false,true]

instead of:

[
  false,
  true
]

which is very verbose IMO (7 bytes more). Maybe even print minified version by default (this command is probably only ever used in scripts anyway) and instead add --prittify for the verbose version.

Same can be done for the YAML version: from

- false
- true

to

[false,true]

(https://yaml.org/spec/1.0/, paragraph 2.1, example 2.5)

I personally haven't heard about YAML minification, but in some cases it is indeed possible (2 bytes saved), so if possible, why not affect both formats?

Use Case

The minified version outputs a smaller result, which if saved as a file, can reduce the size of that file (or reduce the size of piped data if used in a POSIX-compliant shell). If typst query outputs a lot of data, then the size difference becomes more noticeable. And just in general, it's better to not waste any resources if it is possible. Also, since the command is mainly used in scripts, the output doesn't have to be readable.

Activity

  1. added
    feature request
    on May 16, 2024
  2. istudyatuni commented on May 16, 2024

    @istudyatuni
    Contributor

    Yaml is a superset of JSON, so minified yaml could probably just be minified json

  3. Andrew15-5 commented on May 16, 2024

    @Andrew15-5
    ContributorAuthor

    This is true only for YAML 1.2: https://yaml.org/spec/1.2.0/. So if the target YAML parser supports v1.2, then you might as well just choose the JSON output instead of YAML. But this means that for v1.0 and v1.1 this is not true and that YAML minification can have its place in some niche cases (I don't know how widespread each YAML version is).

  4. istudyatuni commented on May 17, 2024

    @istudyatuni
    Contributor

    It turns out, serde_yaml doesn't have a to_string_pretty method, only to_string

  5. Enter-tainer commented on May 17, 2024

    @Enter-tainer
    Contributor

    I don't see why this is useful in any real case other than "I think it's very verbose". For passing json around using pipes, json parsers will skip all white space characters as if they are not exist. It there an example that makes a json file faster to process after minifying it? IIRC people will typically do this when serving them. But i think they already have a good packer to do such thing,

  6. Andrew15-5 commented on May 17, 2024

    @Andrew15-5
    ContributorAuthor

    I already mentioned an overlooked problem — waste of resources (size of the output).

    Now that I think about it, performance can be affected too because you can't prettify an output without wasting more time. For tiny output like that this will be negligible, but when it gets big enough I'm sure the difference is measurable.

    Documents with hundreds of pages do exist and if you query something big in size and/or frequent, then this is how you get big JSON data.

  7. added
    cli
    introspection
    on May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clifeature requestintrospection

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions