1

I have the following input json:

{
  "ListArray": [
    {
      "address": "address1",
      "contact": "123456789",
      "bpId": 123
    },
    {
      "address": "address2",
      "contact": "135792468",
      "bpId": 456
    },
    {
      "address": "address3",
      "contact": "246812356",
      "bpId": 678
    }
  ]
}

And I am using the below spec expression :

[
  {
    "operation": "shift",
    "spec": {
      "ListArray": {
        "*": {
          "*": "&"
        }
      }
    }
  }
]

Giving me this kind of output:

{
 "Address_list": ["address1","address2","address3"],
 "Contact_list": ["123456789","135792468","246812356"],
 "Id_list": [123,456,678]
}

But, If the input (array of jsons) has only one json, for example:

{
  "ListArray": [
    {
      "address": "address1",
      "contact": "123456789",
      "bpId": 123
    }
  ]
}

Then I am getting the following output

{
  "Address_list": "address1",
  "Contact_list": "123456789",
  "Id_list": 123
}

For one element, an array isn't forming. I want the output to be in an array even if there is only one element. Thanks, in advance.

1 Answer 1

1

Just a slight change, which is appending .[] to the currently existing ampersand(&), will resolve this such as

[
  {
    "operation": "shift",
    "spec": {
      "ListArray": {
        "*": {
          "*": "&.[]"
        }
      }
    }
  }
]
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.