Support Questions

Find answers, ask questions, and share your expertise

Jolt - Nearly perfect, just need to remove square brackets

avatar

I'm so close with this but afraid I do need a hand with a jolt transformation. I've done most of the work but can't get the last transformation working. I need to have it output without the square brackets.


Here is my data:

{
"totalElements": 168,
"columns": {
"dimension": {
"id": "variables/daterangehour",
"type": "time"
},
"columnIds": [
"1"
]
},
"rows": [
{
"itemId": "119050300",
"value": "00:00 2019-06-03",
"data": [
120
]
},
{
"itemId": "119050805",
"value": "05:00 2019-06-08",
"data": [
98
]
},
{
"itemId": "119050923",
"value": "23:00 2019-06-09",
"data": [
172
]
}
]
}
}

This is my Jolt:


[{
"operation": "shift",
"spec": {
"rows": {
"*": {
"value": "[&1].date",
"data": "[&1].data"
}
}
}
}
]


It gives me this result:


[ {
"date" : "00:00 2019-06-03",
"data" : [ 120 ]
}, {
"date" : "22:00 2019-06-09",
"data" : [ 307 ]
}, {
"date" : "23:00 2019-06-09",
"data" : [ 172 ]
} ]

This causes my system issues, I actual need the data field like this:


[ {
"date" : "00:00 2019-06-03",
"data" : "120"
}, {
"date" : "05:00 2019-06-08",
"data" : "98"
} ]


How do I pluck the item out of the array / square brackets? It will only ever be one item in there.


1 REPLY 1

avatar
Master Guru

@James Willson


Try with below spec:

[{
    "operation": "shift",
    "spec": {
      "rows": {
        "*": {
          "value": "[&1].date",
          "data": {
            "*": "[#3].data"
          }
        }
      }
    }
}
]

Gives output that you are looking for:

[ {
  "date" : "00:00 2019-06-03",
  "data" : 120
}, {
  "date" : "05:00 2019-06-08",
  "data" : 98
}, {
  "date" : "23:00 2019-06-09",
  "data" : 172
} ]

-

If the answer is helpful to resolve the issue, Login and Click on Accept button below to close this thread.This will help other community users to find answers quickly 🙂