• Instructions to Ask a Question

    For any assistance, please click the "Ask a Question" button and select the Pabbly product for which you require support.

    We offer seven comprehensive applications designed to help you efficiently manage and grow your business:

    Our support team endeavors to respond within 24 business hours (Monday to Friday, 10:00 AM to 6:00 PM IST). We appreciate your understanding and patience.

    🚀 Exclusive Lifetime Offers 🚀

    We invite you to take advantage of our special one-time payment plans, providing lifetime access to select applications:

    • 🔥 Pabbly Connect — Lifetime Access for $249View Offer
    • 🔥 Pabbly Subscription Billing — Lifetime Access for $249View Offer
    • 🔥 Pabbly Chatflow — Lifetime Access for $249View Offer

    Make a one-time investment and enjoy the advantages of robust business management tools for years to come.

Extracting specific values from a JSON string

JoshBeall

Member
In one of my workflows, I am processing a JSON object that looks something like this:


"custom_fields": [
{
"custom_field_definition_id": 426105,
"value": 1754952120
},
{
"custom_field_definition_id": 453167,
"value": false
},
{
"custom_field_definition_id": 458425,
"value": 1537890
},
{
"custom_field_definition_id": 617774,
"value": 1755230400
},
{
"custom_field_definition_id": 424495,
"value": null
}

I want to get the "value" number for the objects that have "custom_field_definition_id" 426105 and 617774.

Is there a no-code way to do this, or do I need to use a JavaScript to parse and return these values? I'm trying to embrace the "no-code" way of doing things, but haven't been able to figure out how to do this without using code.

When I initially built out this workflow, I used an iterator to inspect every one of the objects--but further on in the workflow I want to be able to perform operations that inspect both values (for custom_field_definition_id's 426105 and 617774). The iterator only gives you access to one (the current value in iteration) at a time.
 

Fagun Shah

Well-known member
Here is the code that you can use with Code - Run Javascript action

const data = [
{ "custom_field_definition_id": 426105, "value": 1754952120 },
{ "custom_field_definition_id": 453167, "value": false },
{ "custom_field_definition_id": 458425, "value": 1537890 },
{ "custom_field_definition_id": 617774, "value": 1755230400 },
{ "custom_field_definition_id": 424495, "value": null }
];

const result = data.reduce((acc, item) => {
acc[item.custom_field_definition_id] = item.value;
return acc;
}, {});

return result;

-----------------------------------------------

1756086928285.png
 

ArshilAhmad

Moderator
Staff member
IjU3NjYwNTZhMDYzZjA0M2Q1MjY0NTUzMDUxMzci_pc
Thank you for sharing the workflow. You will need to add a Code step to the workflow to achieve your desired use case. There is no other no-code way to consistently map the data to the next steps.

You can use the code that Fagun shared with us and map the data directly from Code (Pabbly) action step.

In this workflow, we have shown how you can add the JS code to the workflow.

 
Top