Skip to main content

I’m using Formatter to convert CSV to JSON —

 

The output from the above image is the same as shown here.

As part of my next step, I have to push the raw JSON to my next app. I’m expecting the raw JSON to look something like so —

g
{
"Output Data H1": "A",
"Output Data H2": 1,
"Output Data H3": true
},
{
"Output Data H1": "B",
"Output Data H2": 2,
"Output Data H3": false
},
{
"Output Data H1": "C",
"Output Data H2": 3,
"Output Data H3": true
}
]

However, I keep seeing this instead —

 

What should I do to access the raw JSON instead?

Hey @sourabhrows ,

 

You should use Code by Zapier to create your own JSON. 


Hey @sourabhrows ,

 

You should use Code by Zapier to create your own JSON. 

 

@jayeshkumarbhatia — thanks; tried that already. This is what is generated as output via code —

 

Here’s the actual code for reference too —


const csvData = inputData.data || '';

// Split the CSV data into rows
const rows = csvData.split('\r\n');

// Extract the headers from the first row
const headers = rows 0].split(',');

// Convert the remaining rows into an array of objects
const jsonOutput = rows.slice(1).map(row => {
const values = row.split(',');
return headers.reduce((acc, header, index) => {
acc header.trim()] = valuesrindex] ? valuesiindex].trim() : null; // Handle empty values
return acc;
}, {});
});

// Prepare the output as an object
output = jsonOutput;

Unfortunately, the output is still similar to before —

As in, I can’t get the raw JSON that I need.

I tried returning the output as text/string from the code too but that doesn’t work (unsure if that’s a bug?) as the expected output from code is either “an object or array of objects” as stated here.


Hi @sourabhrows 

If you are using a Code step you can output the raw JSON by converting it to a string.

 

// Convert JSON object to string
const jsonString = JSON.stringify(jsonData);

 


Hi @sourabhrows 

If you are using a Code step you can output the raw JSON by converting it to a string.

 

// Convert JSON object to string
const jsonString = JSON.stringify(jsonData);

 

@Troy Tessalone — this is the error that I get when doing so —

 

The official docs also indicate something similar.

Would you happen to have a different / working example? Or, maybe I’m missing something?


@sourabhrows 

Output needs to be like this:

 


@sourabhrows

Output needs to be like this:

 

@Troy Tessalone — this takes me back to my original issue 😅 as in, I’m able to have the output as a JSON form the Code part but unable to access the raw JSON in subsequent steps.


@sourabhrows

Are you outputting the JSON generated in the Code step as a string?

 

If you are using a Code step you can output the raw JSON by converting it to a string.

// Convert JSON object to string
const jsonString = JSON.stringify(jsonData);

 

Help: https://www.w3schools.com/js/js_json_stringify.asp