I realize there are several other JmesPath join questions here, but I'm having trouble with a separate problem that I haven't found any examples for, where I need to concatenate (ie, join) a set of JSON values that have dynamically-named keys into a single element.
If I start with the following JSON data structure:
{
"data": [
{
"secmeetingdays":
{
"dayset_01":
{
"day_01": "M",
"day_02": "W",
"day_03": "F"
},
"dayset_02":
{
"day_01": "T",
"day_02": "TH"
}
},
}]
}
I would like to end up with something like this:
[
[
"M,W,F"
],
[
"T,TH"
]
]
I've started the query to flatten the data down, but am completely stuck with the join syntax. Nothing I try seems to be working.
- Attempt 1:
data[].secmeetingdays | [0].*.*
[
[
"M",
"W",
"F"
],
[
"T",
"TH"
]
]
Almost, but not quite there.
- Attempt 2:
data[].secmeetingdays | [0].*.* | {join(',',@)}
fails
- Attempt 3:
data[].secmeetingdays | [0].*.*.join(',',@)
fails
- Attempt 4:
data[].secmeetingdays | {join(',',@[0].*.*)}
fails
- I tried avoiding 2 flattens to have some reference to grab onto inside the join.
Attempt 4 data[].secmeetingdays | [0].* | join(',',@[]).
fails
- Attempt 6
data[].secmeetingdays | [0].*.* | @.join(',',[])Gives a result, but it's not what I want:
"M,W,F,T,TH"
Update:
- Attempt 7
data[].secmeetingdays[].*.* | [].join(',',@)gets me a lot closer but is also not exactly what I need:
[
"M,W,F",
"T,TH"
]
I might be able to work with this solution, but will leave this open in case someone has the accurate answer to the question.
The example here https://jmespath.org/ has a join, but it is only on a single list of items. How can I join the sub-arrays without affecting the structure of the parents?