claudio gugliotta
claudio gugliotta

Reputation: 191

How to trasform a Json list to a key-value object

I have a Json with this structure:

{"code":"0000",
 "usercode":"sample",
 "specifications":{ 
    "c":"d","e":"f"
}}

I need to build a jolt to convert the json to this form:

{"code":"0000",
 "usercode":"sample",
 "specifications":[
      {"key":"c",
       "value":"d"},
      {"key":"e",
       "value":"f"}
]}

I tried this, but is my first jolt.

[
  {
    "operation": "shift",
    "spec": {
      "code": "code",
      "usercode": "usercode",
      "specifications": {
        "*": {
          "key": "@c",
          "value": "@d"
        }
      }
    }
  }
]

Upvotes: 0

Views: 39

Answers (1)

Lemmerich
Lemmerich

Reputation: 1292

First check this example: https://jolt-demo.appspot.com/#mapToList to understand whats going on :)

This spec will do the trick:

[
  {
    "operation": "shift",
    "spec": {
      "code": "&",
      "usercode": "&",
      "specifications": {
        "*": {
          "$": "&2[#2].key",
          "@": "&2[#2].value"
        }
      }
    }
  }
]

Upvotes: 1

Related Questions