Source JSON:
{
"accounts": [
{
"name": "accounts/189134493",
"createTime": "2021-02-08T08:55:53.722Z",
"updateTime": "2021-02-08T08:55:53.722Z"
},
{
"name": "accounts/192303354",
"createTime": "2021-03-16T14:22:04.865Z",
"updateTime": "2021-03-16T14:22:04.865Z"
}
],
"nextPageToken": "APDpoXMhpjzh_oJqiqip6upnMH"
}
Expected:
[
{
"id": "1891344",
"createTime": "2021-02-08T08:55:53.722Z",
"updateTime": "2021-02-08T08:55:53.722Z"
},
{
"id": "1923033",
"createTime": "2021-03-16T14:22:04.865Z",
"updateTime": "2021-03-16T14:22:04.865Z"
}
]
I was only able to unnest values from accounts array with simple shift operation:
"spec": {
"*": {
"*": {
"*": "[&1].&"
}
}
}
Now I need to grab values from name, and get value after accounts/ and store it as id.
>Solution :
You can successively use split and join functions within a modify transformation such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"accounts": {
"*": {
"name_": "=split('accounts/',@(1,name))", // split the pieces by the provided literal "accounts/"
"id": "=join('',@(1,name_))" // combine the components of the newly formed arrays to yield string type values
}
}
}
},
{
"operation": "remove",
"spec": {
"accounts": {
"*": {
"nam*": ""
}
},
"nextPageToken": ""
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is
