Skip to main content
Solved

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

  • June 13, 2023
  • 1 reply
  • 645 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?

Best answer by Ramy

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!

View original
Did this topic help you find an answer to your question?

1 reply

  • 22 replies
  • Answer
  • June 14, 2023

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings