0

I'm trying to convert a JSON object to an array contained one element

Input :

{
  "record": {
    "file_header": {
      "file_name": "TEST_FILE"
    },
    "scheda_contatto": {
      "phone_number": "5555-111-222-333",
      "type_call": 1
    }
  }
}

i want scheda_contatto to be an array with only 1 element

Output:

{
  "record": {
    "file_header": {
      "file_name": "TEST_FILE"
  },
  "scheda_contatto": [
    {
      "phone_number": "5555-111-222-333",
      "type_call": 1
    }
  ]
 }
}

1 Answer 1

1

You can use &1[0].& in order to nest all innermost sub-elements(&) of the single object by square-brackets([0]) with key name scheda_contatto(&1 under s*) while prefixing each value identifier by &1 and &2 respectively in order to replicate the wrapper key name record for both such as

[
  {
    "operation": "shift",
    "spec": {
      "rec*": {
        "*": "&1.&",
        "s*": {
          "*": "&2.&1[0].&"
        }
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I'm sorry @barbaros-Özhan but I found a problem that I don't know how to solve, in your solution you have deleted record , how can I not delete it?

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.