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"

        }]
    }
1

1 Answer 1

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"
        }
      }
    }
  }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.