Print all fields of a nested json object
Hi, thank you for the useful tool! I have an issue with using the flag "--additional-value".
I'm using fblog v3.0.2 built by myself using Cargo and source code.
The output of execute $ fblog --help:
fblog 3.0.2
Brocode inc <[email protected]>
json log viewer
USAGE:
fblog [FLAGS] [OPTIONS] [--] [INPUT]
...
The problem is that the output does not contain the field I specified using the flag -a.
I have the log message:
{"time": "2021-11-08T13:55:45.924593+00:00", "level": "INFO", "caller": "/app/service/runner.py:58", "message": "Some message here", "process": "1", "thread": "MainThread", "function": "run", "line_no": "58", "module": "runner", "logger": "service.runner", "extra": {"a": 1}}
I want to see a value of the key "extra", so i'm using fblog -a extra and it doesn't work. At the same time, if I use the command fblog -a module, the value of the key module is displayed correctly.
Please help me figure out what I'm doing wrong, or confirm that this is a bug.
This is a missing feature. You can use -a "extra > a" but there is no "wildcard" to select all nested fields.
๐ It might be that I have the same issue. I have the next line:
{"M":"msg","record":[{"aaa":"bbb"}]}
I tried cat json.log | fblog -a'record[1] > aaa' and cat json.log | fblog -a'record[1].aaa'
No luck.
Is it possible to display bbb?
Or maybe it is possible to display the whole record as a string?
Array selection is something that needs improvement.
In general the approach to select specific fields needs a rework. I don't have the time at the moment but I'll look into it eventually.
I know it is not good enough but I usually use -d in those cases.
09:25:20 fblog is ๐ฆ v4.2.0 via ๐ฆ v1.64.0 on ๎ master
ยป cat sample_nested.json.log
{"timestamp":"<>2017-07-06T15:21:16.378+00:00", "log": {"level": "info"}, "status": {"a": 100, "b": "te\nst", "c": true}, "message": "test"}
{"timestamp":"<>2017-07-06T15:21:16.378+00:00", "log": {"level": "info"}, "status": {"a": 200, "b": "sdfdsf", "c": true}, "message": "test"}
{"timestamp":"<>2017-07-06T15:21:16.378+00:00", "log": {"level": "info"}, "status": {"a": 200, "b": "sdfdsf", "c": true, "d": [{"a": 1}, [["a", "b"], [{"x": {"y": "a"}}]], "b"]}, "message": "test"}
09:27:45 fblog is ๐ฆ v4.2.0 via ๐ฆ v1.64.0 on ๎ master
ยป fblog -d sample_nested.json.log
<>2017-07-06T15:21: UNKNO: test
log > level: info
message: test
status > a: 100
status > b: te
st
status > c: true
timestamp: <>2017-07-06T15:21:16.378+00:00
<>2017-07-06T15:21: UNKNO: test
log > level: info
message: test
status > a: 200
status > b: sdfdsf
status > c: true
timestamp: <>2017-07-06T15:21:16.378+00:00
<>2017-07-06T15:21: UNKNO: test
log > level: info
message: test
status > a: 200
status > b: sdfdsf
status > c: true
status > d[1] > a: 1
status > d[2][1][1]: "a"
status > d[2][1][2]: "b"
status > d[2][2][1] > x >: a
status > d[3]: "b"
timestamp: <>2017-07-06T15:21:16.378+00:00
09:27:52 fblog is ๐ฆ v4.2.0 via ๐ฆ v1.64.0 on ๎ master
ยป fblog -a status sample_nested.json.log
<>2017-07-06T15:21: UNKNO: test
status > a: 100
status > b: te
st
status > c: true
<>2017-07-06T15:21: UNKNO: test
status > a: 200
status > b: sdfdsf
status > c: true
<>2017-07-06T15:21: UNKNO: test
status > a: 200
status > b: sdfdsf
status > c: true
status > d[1] > a: 1
status > d[2][1][1]: "a"
status > d[2][1][2]: "b"
status > d[2][2][1] > x >: a
status > d[3]: "b"
09:27:57 fblog is ๐ฆ v4.2.0 via ๐ฆ v1.64.0 on ๎ master
ยป fblog -a 'status > d[1] > a' sample_nested.json.log
<>2017-07-06T15:21: UNKNO: test
<>2017-07-06T15:21: UNKNO: test
<>2017-07-06T15:21: UNKNO: test
status > d[1] > a: 1
```
It is not perfect but is now supports both use cases.
-a status prints the entire status object and -a 'status > d[1] > a' selects something inside an array.