Unwrap Array - need to output single object

I am taking processed data from a segmentation model, and adding the labels to a different json file ultimately outputting 1 updated json file. My issue, is that I need the output to be a single object, and not wrapped in an array. I have tried many different workflows but can’t seem to output a binary json file without an array.

My workflow

I need the output to look something like this without the [ array brackets:
{"id":"LWGUD43SJJ29U","name":"COMBAT ELASTIC GUSSET saddle","size":1712744,"btime":1676073608000,"mtime":1676073608000,"ext":"jpg","tags":["CONSTRUCTION","UPPER"],"folders":["LWGUD43EMNHKO"],"isDeleted":false,"url":"","annotation":"","modificationTime":1716322939969,"height":3024,"width":4032,"lastModified":1716322986212,"palettes":[{"color":[251,251,251],"ratio":66},{"color":[129,99,64],"ratio":25},{"color":[164,130,91],"ratio":6},{"color":[173,158,141],"ratio":0.63},{"color":[156,116,79],"ratio":0.58},{"color":[54,44,32],"ratio":0.35}]}

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

If you had that json you shared without the [ ] then it wouldn’t be valid json. That nested data is an array, so removing the brackets would make the json invalid.

What’s your use case here? Why do you need it out of the array?

Let me know because there is likely a way to make it work with the array, if not I can give you some code that will give you a workaround

hello @Kelly_May

In order to save the json as one Object, change the save mode to Each Item to Separate File
image

@barn4k It seems like they might have one item and are trying to break up arrays nested within the JSON (i think?)

Let me give some context! So, my company uses eagle.cool to store our images, we store the library directory for the app in box. Everytime an image is uploaded to eagle, a folder in box is created with the jpg and the metadata.json. I would like to take the labels created from the image segmentation model, and add them to the metadata.json and reupload to box so that the tags show up in eagle.coo

The original metadata.json that eagle creates looks like this
{"id":"LWGUD43SJJ29U","name":"COMBAT ELASTIC GUSSET saddle","size":1712744,"btime":1676073608000,"mtime":1676073608000,"ext":"jpg","tags":[],"folders":["LWGUD43EMNHKO"],"isDeleted":false,"url":"","annotation":"","modificationTime":1716322939969,"height":3024,"width":4032,"lastModified":1716322986212,"palettes":[{"color":[251,251,251],"ratio":66},{"color":[129,99,64],"ratio":25},{"color":[164,130,91],"ratio":6},{"color":[173,158,141],"ratio":0.63},{"color":[156,116,79],"ratio":0.58},{"color":[54,44,32],"ratio":0.35}]}

The output I currently get, has the array brackets and its not compatible with eagle.cool metadata

Ok, just so i understand correctly you want to go from this:

[
  {
    "json": "Place holder"
  }
]

to this?

{
  "json": "Place holder"
}

Or you want to remove brackets from deep within that json?

That’s why you need to change that setting I have specified previously :wink:

1 Like

Nope, they want to save a json object in the file as an object. But by default n8n will save it as an array of one item

correct! that is what I am looking to get

you are a magician! that worked, thanks so much

Now…

my new problem is that this correct json file uploaded to box, but seems to not be recognized by box, therefore not showing the tags in eagle.cool

I have attached a couple pictures to show you what I am working with!


Can’t say much about it :slight_smile:

You should check how your box app updates the eagle image

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