Cross join nested data #104
Answered
by
springcomp
eddycharly
asked this question in
Q&A
-
What is the simplest way to transform data: {
"states": [
{"name": "WA", "cities": ["Seattle", "Bellevue", "Olympia"]},
{"name": "CA", "cities": ["Los Angeles", "San Francisco"]},
{"name": "NY", "cities": ["New York City", "Albany"]}
]
} Into: [
{ "name": "WA", "city": "Seattle" },
{ "name": "WA", "city": "Bellevue" },
{ "name": "WA", "city": "Olympia" },
{ "name": "CA", "city": "Los Angeles" },
{ "name": "CA", "city": "San Francisco" },
{ "name": "NY", "city": "New York City" },
{ "name": "NY", "city": "Albany" }
] That is, iterating over states and cities and producing one object per state and city combination ? cc @springcomp 🙏 |
Beta Was this translation helpful? Give feedback.
Answered by
springcomp
Sep 12, 2024
Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
eddycharly
-
Thanks @springcomp ! I was hoping there was a solution without using |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@eddycharly
map(&let $n=name, $cs=cities in map(&{name: $n, city:@}, $cs), @.states)[]