J.Zil
J.Zil

Reputation: 2449

Minor Jolt JSON modification - Take figure out of single array

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 minute transformation working.

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.

Upvotes: 1

Views: 184

Answers (1)

Magda
Magda

Reputation: 482

You should go deeper and take value. Is it clear for you?

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

And if you need Strings add this:

  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "data": "=toString"
      }
    }
  }

Upvotes: 1

Related Questions