Transform values into Key of next Json

Describe the issue/error/question

Hello! I am super stuck. I have a list with 2 columns “Key” and “Values” . I need to make the values inside the column “Key” , the actual Key’s of the Json i want to send, and the values in the column “Values” the values of the corresponding keys… To clarify, here is an example:

[
{
"id": 22766366654681,
"namespace": "my_fields",
"key": "material",
"value": "Leather",
"description": null,
"owner_id": 7570081644761,
"created_at": "2022-02-28T14:19:34+01:00",
"updated_at": "2022-02-28T14:19:34+01:00",
"owner_resource": "product",
"type": "single_line_text_field",
"admin_graphql_api_id": "gid://shopify/Metafield/22766366654681"
},
{
"id": 22766366687449,
"namespace": "my_fields",
"key": "universe",
"value": "Women",
"description": null,
"owner_id": 7570081644761,
"created_at": "2022-02-28T14:19:34+01:00",
"updated_at": "2022-02-28T14:19:34+01:00",
"owner_resource": "product",
"type": "single_line_text_field",
"admin_graphql_api_id": "gid://shopify/Metafield/22766366687449"
},
{
"id": 22766366720217,
"namespace": "my_fields",
"key": "category",
"value": " ",
"description": null,
"owner_id": 7570081644761,
"created_at": "2022-02-28T14:19:34+01:00",
"updated_at": "2022-02-28T14:19:34+01:00",
"owner_resource": "product",
"type": "single_line_text_field",
"admin_graphql_api_id": "gid://shopify/Metafield/22766366720217"
},

I need this to output:

{
"Shopify Id": 7570081644761,
"material": "Leather",
"universe": "Women",
"category" : "",
}

I tried many things, mainly nesting IF statements and set nodes to identify the values and restructure the Json. but it didnt work…

Then i tried nesting merge nodes with the optiont of “merge outputs”, but it is super annoying because if one of the values is empty, the output will be empty, and if i use the “append” option, then since i do multiple levels of merging i end up with rows with the same ID at the end …

Important to note than I have 11 Keys so it is quite a long list of nested merging, and many times the values are empty

Please help! and LMK if something isnt clear ill be reactive!
thanks so much to whomever can help me

Here is my workflow:


Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]:

Hi @oly-dev

try this:

2 Likes

OMG it works! however, how can i then change the name of the keys from material to Metafield_material etc. ?

Knowing that one input might have the key’s : material, subcategory and the next input might have brand and color only …

that is why i was doing the IF functions … so it would need to be something like: IF the key present is material, then map that to Metafield_material, IF the key color is present, then map to MEtafield_color etc…

newItem.json[‘metafield_’+item.json.key] = item.json.value;

this maybe?

2 Likes

Thanks for your help! I ended up using a SET node and works perfect!

Thanks so much!!!

1 Like

i have a new question, here in case you have some insight Trigger part 2 of workflow when splitbatches finishes

Hello I’m sstruggling with another issue trying to parse a Json for some values, could you help me? Turn array into string for google sheet

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