Search code examples
jsontransformjsonata

Merging the object having array in JSONata into array of objects


I need to merge the array item to object using JSONata If my input is

{"skus":[
  {
    "a":1,
    "c":3,
    "b":["n"]
  },
  {
    "a":6,
    "c":7,
    "b":["f","h"]
  }]}

I need output as below. I need it to be expanded within same object

{"skus":[
  {
    "a":1,
    "c":3,
    "b":"n"
  },
  {
    "a":6,
    "c":7,
    "b":"f"
  },
  {
    "a":6,
    "c":7,
    "b":"h"
  }]}


Solution

  • {
        "skus":skus.$.b.
        {
            "a": %.a,
            "c":%.c,
            "b":$
        }
    }
    

    This is the JSONata spec. Try it https://try.jsonata.org/P5E2v0FNn