0

It's been very easy with DataWeave in Apex to convert a JSON to a csv. However, I'm getting a JSON from a REST call, and the part I'm interested in is located in the "data" property, something like that (simplified):

{
    "current_page": 1,
    "data": [
        {
            "id": 2854701,
            "person": "6116"
        },
        {
            "id": 2854702,
            "person": "6116"
        }
    ]
}

Do I have a way to only use the content of the data property for the DataWeave transformation ? I guess I could create an Apex class to parse everything, keep only the data part and parse it again to csv but I would like to avoid that.

1 Answer 1

2

Well I would have better read the DataWeave documentation before asking before it turns out it's damn simple, I was just not understanding how DataWeave works and its syntax.

Whereas the basic .dwl file I had to convert json to csv was like this:

%dw 2.0 
input payload application/json
output application/csv
--- 
payload

I just had to change the latest part of the script to select what's exported:

%dw 2.0 
input payload application/json
output application/csv
--- 
payload.data

So it's actually a pretty stupid question, but as DataWeave is coming to Apex and I guess some other folks may be as new to it as I am, this may be useful to another "I don't read the doc long enough" fellow like me.

To experiment the DataWeave Playground is definitely a great tool.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .