Solved

How do I update a specific nested JSON property via Create or Update workflow action?

  • 13 June 2023
  • 1 reply
  • 368 views

I have an attribute “last_estima” that stores a json object that looks like this

I want to update only the “date” field in the create or update workflow :

but when this runs, a new “last_estima.date” attribute is created rather then the nested “date” field being updated

I know it is possible to update the whole “last_estima” attribute at once, but is it possible to edit just the “date” property without having to set the rest of the object too?

icon

Best answer by Ramy 14 June 2023, 11:52

View original

1 reply

Userlevel 1
Badge

Hi there!

 

Thank you for posting to our community, We’re happy to help you here!

 

I’m afraid it is not possible to update nested JSON attributes using Liquid. The reason your current flow creates a new attribute, is because the “value” you enter in the “Attribute” field in your Create or Update Person action does not exist, so Customer.io creates an attribute with this name.

With that said, you can absolutely achieve what you’re looking for using simple JavaScript code. You would select the “Attribute” as “last_estima”, and here’s a snippet of what that code could look like:

const jsonObject = customer.last_estima;

// Convert the provided date string to a Unix timestamp
const unixTimestamp = new Date(jsonObject.date).getTime() / 1000;

// Update the "date" field in the JSON object with the Unix timestamp
jsonObject.date = unixTimestamp;

// return the updated JSON object value
return(jsonObject);

I hope this is helpful! Let us know if you run into any trouble with this!

Reply