benibela / xidel

Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
http://www.videlibri.de/xidel.html
GNU General Public License v3.0
674 stars 42 forks source link

[Request] Strip excessive whitespace when exporting JSON with --output-format={bash|cmd} #71

Closed Reino17 closed 3 years ago

Reino17 commented 3 years ago

Linux:

$ xidel -s '{"a":1,"b":"x y z","c":null}' -e '$json' --output-format=bash
result='{"a": 1, "b": "x y z", "c": null}'

Windows:

xidel -s "{'a':1,'b':'x y z','c':null}" -e "$json" --output-format=cmd
SET result={^"a^": 1^, ^"b^": ^"x y z^"^, ^"c^": null}

It's almost as if the JSON input is serialized with serialize-json() as opposed to serialize():

xidel -s '{"a":1,"b":"x y z","c":null}' -e 'serialize-json($json)'
{"a": 1, "b": "x y z", "c": null}

xidel -s '{"a":1,"b":"x y z","c":null}' -e 'serialize($json,{"method":"json"})'
{"a":1,"b":"x y z","c":null}

(isn't serialize-json() unnecessary/superfluous now?)

Probably less a concern on Linux, but Windows cmd its commandline buffer is only 8KB. So cmd variables can only hold a max of 8192 characters.
With that in mind can you please strip excessive whitespace, like serialize() does, when exporting JSON with --output-format={bash|cmd}, Benito?

Reino17 commented 3 years ago

One month later. Can you at least share your opinion on the matter?

benibela commented 3 years ago

It's almost as if the JSON input is serialized with serialize-json() as opposed to serialize():

yes

One month later.

Already? It feels like yesterday

Can you at least share your opinion on the matter?

it is not so easy to change

Reino17 commented 3 years ago

Very nice. Thank you very much!