JSON to CSV
The /json_to_csv endpoint converts the given JSON data to CSV data. This endpoint also supports nested JSON.
Method: POST
To make a request, send the required parameters with the authorization header to the /json_to_csv endpoint, via the POST method.
Parameters
This endpoint takes only two parameters, namely, source_json and options.
source_jsonis the JSON data which is to be converted to CSV.optionsis an object containing the customization options for the conversion. Supported customization options are:flatten_nestedis a boolean value determining whether to flatten the nested JSON objects or keep it as it is.nested_key_separatoris the character which would be used to join the keys of the nested values. It is ignored ifflatten_nestedisfalse.default_valueis the value to use when data is missing. Default is''(empty string)include_empty_rowsis a boolean which determines whether to include empty rows.with_bomis a boolean which determines whether to use BOM (Byte-order mark) character. Default isfalse
Responses
The success response, when flatten_nested is true and nested_key_separator is .:
{
"status": "success",
"data": {
"source_json": [
{
"id": 1,
"name": "John Doe",
"contact": {
"email": "john.doe@example.com"
}
},
{
"id": 2,
"name": "Jane Doe",
"contact": {
"email": "jane.doe@example.com"
}
}
],
"csv": "\"id\",\"name\",\"contact.email\"\n1,\"John Doe\",\"john.doe@example.com\"\n2,\"Jane Doe\",\"jane.doe@example.com\"",
"options_applied": {
"flatten_nested": true,
"nested_key_separator": "."
}
},
"message": "JSON has been successfully converted to CSV."
}
JSON
When, flatten_nested is false:
{
"status": "success",
"data": {
"source_json": [
{
"id": 1,
"name": "John Doe",
"contact": {
"email": "john.doe@example.com"
}
},
{
"id": 2,
"name": "Jane Doe",
"contact": {
"email": "jane.doe@example.com"
}
}
],
"csv": "\"id\",\"name\",\"contact\"\n1,\"John Doe\",\"{\"\"email\"\":\"\"john.doe@example.com\"\"}\"\n2,\"Jane Doe\",\"{\"\"email\"\":\"\"jane.doe@example.com\"\"}\"",
"options_applied": {
"flatten_nested": false,
"nested_key_separator": "."
}
},
"message": "JSON has been successfully converted to CSV."
}
JSON
And if some error occurs, like invalid JSON:
{
"status": "error",
"error": {
"code": "INVALID_JSON",
"message": "Unable to parse JSON string.",
"details": "Unexpected token 'H', \"Hehe\n{\n\t\"i\"... is not valid JSON"
}
}
JSON