Define format in jq code
The proposed change makes it easier to extend format with new formats (#1227). The reasoning is that it is often more straightforward to implement a serialization algorithm recursively in a high-level functional language than in C.
I've implemented serialization to Tcl dictionaries (#685) in pure jq code as an example. This version differs slightly from the one in #685 to work around forward slash (\) escaping issues in src/builtin.jq.
Perhaps the function Edit: Done.totcl should be renamed _totcl.
Coverage increased (+0.02%) to 85.35% when pulling 19f2e61c997347481d02ae73370cfe5204980d0c on dbohdan:format-in-jq into 0b8218515eabf1a967eba0dbcc7a0e5ae031a509 on stedolan:master.
Coverage increased (+0.02%) to 85.35% when pulling 7ec1d73351e1a45e5193db3f4bb0038623eeb111 on dbohdan:format-in-jq into 0b8218515eabf1a967eba0dbcc7a0e5ae031a509 on stedolan:master.
Coverage increased (+0.4%) to 85.769% when pulling a1c93d9e1c6b4171ac83efa66c4bd86929a4990a on dbohdan:format-in-jq into 0b8218515eabf1a967eba0dbcc7a0e5ae031a509 on stedolan:master.
Hi. This is a wonderful contribution. I may leave totcl that way instead of as _totcl; not sure. I'll try to get to merging this this coming weekend. Thanks!
Great!
I've realized there is a corner case that can cause @tcl to produce invalid Tcl data. I'll make a test for it and produce a patch shortly.
Done. Now @tcl quotes data the way Tcl itself does. I've added tests for some corner cases that the earlier implementation failed to process correctly. I didn't rename _totcl back to totcl to leave that up to you.
I forgot to say that I appreciate you complimenting this change. I am a fan of the purely functional language that jq has grown.
Ping. Any updates on this?
I'd love to see this in jq. I could see this formatter plugin being used to output YAML, hocon, dhall, and some others that are effectively supersets of JSON.