Input json:
[
{
"Authors": "Author1, Author2, Author3",
"Affiliation": "Here, There, Everywhere"
},
{
"Authors": "Author4, Author5",
"Affiliation": "Nirvana, Utopia"
}
]
Desired output:
{
"authors": [
{
"Name": "Author1",
"Affiliation": "Here"
},
{
"Name": "Author2",
"Affiliation": "There"
},
{
"Name": "Author3",
"Affiliation": "Everywhere"
}
]
},
{
"authors": [
{
"Name": "Author4",
"Affiliation": "Nirvana"
},
{
"Name": "Author5",
"Affiliation": "Utopia"
}
]
}
I can read the first elements of both arrays with:
jq '.[] as $o | $o.Authors | split(", ") as $authors | $o.Affiliation | split(", ") as $affiliation | { "Authors": [ { "Name": $authors[.0], "Affiliation": $affiliation[.0]} ] }'
but I'm struggling to understand how to get jq to iterate over the entire (arbitrary length) string to produce the full desired output.