You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add ability to produce minified JSON (and perhaps YAML) output by typst query #4157
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.
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.
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).
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,
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.
Activity
istudyatuni commentedon May 16, 2024
Yaml is a superset of JSON, so minified yaml could probably just be minified json
Andrew15-5 commentedon May 16, 2024
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).
istudyatuni commentedon May 17, 2024
It turns out,
serde_yamldoesn't have ato_string_prettymethod, onlyto_stringEnter-tainer commentedon May 17, 2024
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,
Andrew15-5 commentedon May 17, 2024
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.