Vikash
Vikash

Reputation: 21

Convert TEXT file to JSON in Dataweave

How can I convert TEXT file into JSON in Dataweave.

Input:

"[
  {
    "quantity": "1.0",
    "uom": "every",
    "amount": "5.0",
    "allocation": [
      {
        "ID": "22245",
        "price": "156",
        "desc": "Product A1"
      }
    ],
  },
  {
    "quantity": "2.0",
    "uom": "all",
    "amount": "65888",
    "allocation": [
      {
        "ID": "65665",
        "price": "7789",
        "desc": "Product A2"
      }
    ],
  }
]"

Expected output in JSON:

ex:
[
  {
    "quantity": "1.0",
    "uom": "every",
    "amount": "5.0",
    "allocation": [
      {
        "ID": "22245",
        "price": "156",
        "desc": "Product A1"
      }
    ],
  },
  {
    "quantity": "2.0",
    "uom": "all",
    "amount": "65888",
    "allocation": [
      {
        "ID": "65665",
        "price": "7789",
        "desc": "Product A2"
      }
    ],
  }
]

enter image description here

Upvotes: 2

Views: 2861

Answers (1)

aled
aled

Reputation: 25699

Use the read() function to parse the input string as JSON.

{
  ex: read(payload,"application/JSON")
}

Upvotes: 3

Related Questions