Skip to content

How to map split strings from file into fields with jq? #3197

Closed Answered by wader
drankinatty asked this question in Q&A
Discussion options

You must be logged in to vote

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"
  }
]

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@drankinatty
Comment options

@wader
Comment options

Answer selected by drankinatty
Comment options

You must be logged in to vote
2 replies
@drankinatty
Comment options

@wader
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants