0

I was trying to have a key value pair mapped to an array, distinguishing each value as a type using jolt transform spec

Input json

{
"testurl": "someurl",
"website": "someurl2"
}

tried this spec



[
  {
    "operation": "shift",
    "spec": {
      "testurl": "Urls[].testurl",
      "website": "Urls[].website"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Urls": {
        "*": {
          "$": "Urls[&1].val"    
        }
      }
    }
  }
]

Expected result is like this

{
        "Urls": [{
            "url": "someurl",
            "val": "testurl"
        }, {
            "url": "someurl2",
            "val": "website"

        }]
    }
Sandeep Raikar
  • 491
  • 1
  • 6
  • 13
  • @Milo S can you answer this https://stackoverflow.com/questions/44144846/json-jolt-shift-specification-for-duplicate-keys-with-different-value-types – g. thornton May 23 '17 at 21:06

1 Answers1

3

Yes you can turn a set of Json key,value pair into an array.

It requires 2 shifts to be safe.

1st shift isolates all the properties you want to turn into an array.

2nd shift is able to use a "*" to then match all those items and place them an array.

Spec

[
  {
    "operation": "shift",
    "spec": {
      "testurl": "temp.testurl",
      "website": "temp.website"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "temp": {
        "*": {
          "$": "Urls[#2].val",
          "@": "Urls[#2].url"
        }
      }
    }
  }
]
Milo S
  • 4,466
  • 1
  • 19
  • 22