Skip to main content

Hi,

I want to put a json object inside one cell in a CSV file. For ex,

{

name: "mule",

address: {

"state":"xxxx",

"country":"yyyy"

}

}

 

Now I want to insert this into CSV with two columns (name, address) and entire address object should get inserted under address column.

 

Please help on achieving this using Dataweave 2.0

3 answers
  1. Feb 21, 2020, 4:41 PM

    HI @Ramkumar K​ ,

    When you are going to transform, use the following script:

    %dw 2.0

    output application/csv quoteValues=true

    var data = {

    state: "xxxx",

    country: "yyyy"

    }

    ---

    [

    { a: 'a',

    b: 'b',

    c: write(data, 'application/json')

    },

    { a: 'a',

    b: 'b',

    c: write(data, 'application/json')

    }

    ]

    Later, whenever you wants to read the data from csv, then use the following metadata:

    HI @Ramkumar K​ ,When you are going to transform, use the following script:%dw 2.

     

    Some Screenshots for your reff:

    1. My first transform to store JSON into CSV.1
    2. Now check my second transform where I tried to read the csv and convert it to JSON using the metadata mentioned in the first pic.

    1

     

    Regards,

     

    Lalit Panwar

0/9000