How to handle a json array log #11248
-
Input: vector.yaml: transforms: Running : How to deal with base source file as JSON array input and how to read the whole json object (1st object) and keep it in memory? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @satscreate, First off I think you "running" command is a bit off, you should use jq -c '.' sample.jsonl | vector -c vector.yaml
2022-02-08T16:41:38.530333Z INFO vector::app: Log level is enabled.
...
{"host":"COMP-C02F514NML87","id":"1","source_type":"stdin","timestamp":"2022-02-08T16:41:38.532531Z","val":"1.0"}
{"host":"COMP-C02F514NML87","id":"2","source_type":"stdin","timestamp":"2022-02-08T16:41:38.532531Z","val":"2.0"} Today the decoding feature is always going to parse and merge the object into the root of the event, for example your object of transforms:
patch:
type: remap
inputs:
- stdin
source: |-
obj = {"id": .id, "val": .val}
log(obj, level: "warn", rate_limit_secs: 0) ... results in: 2022-02-08T16:46:56.181324Z WARN vrl_stdlib::log: { "id": "1", "val": "1.0" } internal_log_rate_secs=0 vrl_position=31
2022-02-08T16:46:56.181352Z WARN vrl_stdlib::log: { "id": "2", "val": "2.0" } internal_log_rate_secs=0 vrl_position=31
{"host":"COMP-C02F514NML87","id":"1","source_type":"stdin","timestamp":"2022-02-08T16:46:56.181147Z","val":"1.0"}
{"host":"COMP-C02F514NML87","id":"2","source_type":"stdin","timestamp":"2022-02-08T16:46:56.181147Z","val":"2.0"} BTW, you can use use triple backticks to code format in Github - ``` |
Beta Was this translation helpful? Give feedback.
Hi @satscreate,
First off I think you "running" command is a bit off, you should use
jq -c '.' sample.jsonl | vector -c vector.yaml
instead. Thejson
decoder on yourstdin
source is going to take your array of objects and parse them into two events:Today the decoding feature is always going to parse and merge the object into the root of the event…