2 years ago

#66640

test-img

navarro_leo

Access properties of an object via Dust.js after running JSON Parse filter

Is there any way to access properties of an object that was transformed into JSON through the jp (JSON parse) filter of Dust.js?

{
    "response": {
        "services": [
            "{
                \"prop1\":\"value1\",
                \"prop2\":\"value2\",
                \"prop3\":10
            }"
        ]
    }
}

For example, with the input above, I intend to receive the following output:

[
    {
        "prop1": "value1"
    }
]

Note that the values inside the service array are strings, and because of that, before accessing the object's properties, I need to run JSON parse filter.

[
    {#response.services}
        {
            "prop1": "{.|jp}"
        }{@sep}, {/sep}
    {/response.services}
]

What I've developed so far is the code above, and this code is returning the following output:

[
    {
        "prop1": "[object Object]"
    }
]

In short, what I need to do is increment this {.|jp} into something where I can access the properties of the returned object, without adding new filters.

Thanks in advance to everyone who is willing to help!

json

gateway

api-gateway

dust.js

0 Answers

Your Answer

Accepted video resources