How to map split strings from file into fields with jq? #3197
-
This seems simple (and it is for those skilled with
I am trying to read the file into a json document with the normal array of arrays structure but giving the words and definitions tags of
Testing with
But when I try to I suspect I need to take the result of How do I simply add the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi, your close! maybe something like this? $ echo -e 'a|b\nc|d' | jq -nR '[inputs | split("|") | {word: .[0], defn: .[1]}]'
[
{
"word": "a",
"defn": "b"
},
{
"word": "c",
"defn": "d"
}
] |
Beta Was this translation helpful? Give feedback.
-
@drankinatty - Nice question. I hope you'll find your jq explorations worthwhile. For future reference, please ask usage questions at stackoverflow.com, not least because that will likely help others find good questions and helpful answers. |
Beta Was this translation helpful? Give feedback.
Hi, your close! maybe something like this?