1
1
mirror of https://github.com/wader/fq.git synced 2025-01-08 07:28:34 +03:00
fq/format/json/testdata/tofromjson.fqtest
Mattias Wadman 8d69f1fb23 interp: Change default bits_format=string
I think this is more intuitive but might in some case cause very large JSON output
but maybe that less common or expected. In does cases i think you either want to
use some other bits_format (md5, truncate, etc) or you delete/transform the jq value
before turn it into JSON.

Strings in gojq are binary safe so you can use to hold raw bytes. But note that
convert the binary into JSON is lossy, same as the JSON standard.

Add bits_format option documentation.
2022-12-01 17:49:34 +01:00

79 lines
2.0 KiB
Plaintext

$ fq -d json . test.json
{
"a": 123,
"b": [
1,
2,
3
],
"c:": "string",
"d": null,
"e": 123.4
}
$ fq -d json tovalue test.json
{
"a": 123,
"b": [
1,
2,
3
],
"c:": "string",
"d": null,
"e": 123.4
}
$ fq . test.json
{
"a": 123,
"b": [
1,
2,
3
],
"c:": "string",
"d": null,
"e": 123.4
}
$ fq .b[1] test.json
2
$ fq . json.gz
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: json.gz (gzip)
0x000|1f 8b |.. | identification: raw bits (valid)
0x000| 08 | . | compression_method: "deflate" (8)
0x000| 00 | . | flags{}:
0x000| 65 0a 08 61 | e..a | mtime: 1627916901 (2021-08-02T15:08:21Z)
0x000| 00 | . | extra_flags: 0
0x000| 03 | . | os: "unix" (3)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0|7b 22 61 22 3a 20 31 32 33 7d 0a| |{"a": 123}.| | uncompressed: {} (json)
0x000| ab 56 4a 54 b2 52| .VJT.R| compressed: raw bits
0x010|30 34 32 ae e5 02 00 |042.... |
0x010| 20 ac d2 9c | ... | crc32: 0x9cd2ac20 (valid)
0x010| 0b 00 00 00| | ....|| isize: 11
$ fq tovalue json.gz
{
"compressed": "\ufffdVJT\ufffdR042\ufffd\ufffd\u0002\u0000",
"compression_method": "deflate",
"crc32": 2631052320,
"extra_flags": 0,
"flags": {
"comment": false,
"extra": false,
"header_crc": false,
"name": false,
"reserved": 0,
"text": false
},
"identification": "\u001f\ufffd",
"isize": 11,
"mtime": 1627916901,
"os": "unix",
"uncompressed": {
"a": 123
}
}
$ fq .uncompressed json.gz
{
"a": 123
}