Not able to send JSON in correct format

Hi Team
In one of my workflow I am fetching a array of json objects from code node and sending it to HTTP request node.
I am trying to access the output of code node using {{$('Code).all() }} which is returning output in below format

[Array: [{"json": {"in_stock_count": 7, "variant_id": "6454f2304f26828807630fbc", "minimum_stock_count": 0, "available_for_sale_count": 7, "reserved_count": 0}, "pairedItem": {"item": 0}},{"json": {"in_stock_count": 4, "variant_id": "6454f2304f26828807630f9e", "minimum_stock_count": 0, "available_for_sale_count": 4, "reserved_count": 0}, "pairedItem": {"item": 1}},{"json": {"in_stock_count": 12, "variant_id": "6454f2304f26828807630fcc", "minimum_stock_count": 0, "available_for_sale_count": 12, "reserved_count": 0}, "pairedItem": {"item": 2}},{"json": {"in_stock_count": 15, "variant_id": "6454f2304f26828807630fa2", "minimum_stock_count": 0, "available_for_sale_count": 15, "reserved_count": 0}, "pairedItem": {"item": 3}}]]

however I need this json in below format

[
{
“in_stock_count”: 7,
“variant_id”: “6454f2304f26828807630fbc”,
“minimum_stock_count”: 0,
“available_for_sale_count”: 7,
“reserved_count”: 0
},
{
“in_stock_count”: 4,
“variant_id”: “6454f2304f26828807630f9e”,
“minimum_stock_count”: 0,
“available_for_sale_count”: 4,
“reserved_count”: 0
},
{
“in_stock_count”: 12,
“variant_id”: “6454f2304f26828807630fcc”,
“minimum_stock_count”: 0,
“available_for_sale_count”: 12,
“reserved_count”: 0
},
{
“in_stock_count”: 15,
“variant_id”: “6454f2304f26828807630fa2”,
“minimum_stock_count”: 0,
“available_for_sale_count”: 15,
“reserved_count”: 0
}
]

Please suggest me changes I need to do.

Hi @Rohit_Mali, the json key would be part of the n8n data structure and thus can’t easily be removed.

Depending on what exactly you need to do with your items, you could however work around this. Assuming you want send this data to an API, a workflow like this would do the job:

The Item Lists node in this example converts your full n8n items into a single item with a new data field (which uses the format you are looking for).

The example workflow then sends it to a URL provided by webhook.site allowing you to easily inspect the data:

Of course you can also use it in any other node instead :slight_smile:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.