mirror of
https://github.com/wader/fq.git
synced 2024-12-28 08:02:28 +03:00
dump,json: Properly figure if compound or not
This commit is contained in:
parent
0a97f86f32
commit
f8e5944f91
8
format/json/testdata/json.fqtest
vendored
8
format/json/testdata/json.fqtest
vendored
@ -2,7 +2,8 @@
|
||||
/json.gz:
|
||||
$ fq -d json . /test.json
|
||||
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |
|
||||
| | |.: {} /test.json (json)
|
||||
0x00|7b 0a 20 20 20 20 22 61 22 3a 20 31 32 33 2c 0a|{. "a": 123,.|.: {} /test.json (json)
|
||||
* |until 0x74.7 (end) (117) | |
|
||||
$ fq -d json tovalue /test.json
|
||||
{
|
||||
"a": 123,
|
||||
@ -17,7 +18,8 @@ $ fq -d json tovalue /test.json
|
||||
}
|
||||
$ fq . /test.json
|
||||
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |
|
||||
| | |.: {} /test.json (json)
|
||||
0x00|7b 0a 20 20 20 20 22 61 22 3a 20 31 32 33 2c 0a|{. "a": 123,.|.: {} /test.json (json)
|
||||
* |until 0x74.7 (end) (117) | |
|
||||
$ fq .b[1] /test.json
|
||||
2
|
||||
$ fq . /json.gz
|
||||
@ -57,4 +59,4 @@ $ fq tovalue /json.gz
|
||||
}
|
||||
$ fq .uncompressed /json.gz
|
||||
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |
|
||||
| | |.uncompressed: {} (json)
|
||||
0x0|7b 22 61 22 3a 20 31 32 33 7d |{"a": 123} |.uncompressed: {} (json)
|
||||
|
@ -24,6 +24,15 @@ const (
|
||||
colField = 6
|
||||
)
|
||||
|
||||
func isCompound(v *decode.Value) bool {
|
||||
switch v.V.(type) {
|
||||
case decode.Struct, decode.Array:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func dumpEx(v *decode.Value, cw *columnwriter.Writer, depth int, rootV *decode.Value, rootDepth int, addrWidth int, opts Options) error {
|
||||
deco := opts.Decorator
|
||||
// no error check as we write into buffering column
|
||||
@ -75,8 +84,6 @@ func dumpEx(v *decode.Value, cw *columnwriter.Writer, depth int, rootV *decode.V
|
||||
rootIndent := strings.Repeat(" ", rootDepth)
|
||||
indent := strings.Repeat(" ", depth)
|
||||
|
||||
isSimple := false
|
||||
|
||||
if depth == 0 {
|
||||
switch v.V.(type) {
|
||||
case decode.Struct:
|
||||
@ -152,8 +159,6 @@ func dumpEx(v *decode.Value, cw *columnwriter.Writer, depth int, rootV *decode.V
|
||||
if v.Description != "" {
|
||||
cfmt(colField, fmt.Sprintf(" (%s)", deco.Value.F(v.Description)))
|
||||
}
|
||||
|
||||
isSimple = true
|
||||
}
|
||||
|
||||
if opts.Verbose {
|
||||
@ -245,8 +250,8 @@ func dumpEx(v *decode.Value, cw *columnwriter.Writer, depth int, rootV *decode.V
|
||||
// log.Printf("opts: %#+v\n", opts)
|
||||
// log.Printf("depth: %#+v\n", depth)
|
||||
|
||||
// has length and is a simple value or a collapsed struct/array
|
||||
if v.Range.Len > 0 && (isSimple || (opts.Depth != 0 && opts.Depth == depth)) {
|
||||
// has length and is not compound or a collapsed struct/array (max depth)
|
||||
if v.Range.Len > 0 && (!isCompound(v) || (opts.Depth != 0 && opts.Depth == depth)) {
|
||||
cfmt(colAddr, "%s%s\n",
|
||||
rootIndent, deco.DumpAddr.F(num.PadFormatInt(startLineByte, opts.AddrBase, true, addrWidth)))
|
||||
|
||||
|
2
pkg/interp/testdata/value_json_array.fqtest
vendored
2
pkg/interp/testdata/value_json_array.fqtest
vendored
@ -2,7 +2,7 @@
|
||||
$ fq -i -n '"[]" | json'
|
||||
json> (.) | ., tovalue, type, length?
|
||||
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |
|
||||
| | |.: [0] unnamed (json)
|
||||
0x0|5b 5d| |[]| |.: [0] unnamed (json)
|
||||
[]
|
||||
"array"
|
||||
0
|
||||
|
2
pkg/interp/testdata/value_json_object.fqtest
vendored
2
pkg/interp/testdata/value_json_object.fqtest
vendored
@ -2,7 +2,7 @@
|
||||
$ fq -i -n '"{}" | json'
|
||||
json> (.) | ., tovalue, type, length?
|
||||
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |
|
||||
| | |.: {} unnamed (json)
|
||||
0x0|7b 7d| |{}| |.: {} unnamed (json)
|
||||
{}
|
||||
"object"
|
||||
0
|
||||
|
Loading…
Reference in New Issue
Block a user