Filter nested JSON in Word template

I have a nestad JSON below, how can I set up filter in the Word template to filter only all the s rows when d="D" Or d="H"

I have tested this: {{D = value.s|filter(value.s.d ="H" || value.s.d="D")}}
and {{D = s|filter(value.d ="H" || value.d="D")}} and {{D = s|filter(value.d ="H" || value.d="D")}}

It doesn't work. See my template in the attached screenshot

[
    {
        "name": "Project Management  ",
        "totalhours": " 56",
        "disciplinedescription": "",
        "s": [
            {
                "header": "Project Management",
                "subheader": null,
                "name": null,
                "example": null,
                "notes": null,
                "res": null,
                "res": null,
                "d": "H",
                "L": "0"
            },
            {
                "header": null,
                "subheader": "Project Execution Plan Includes:",
                "name": null,
                "example": null,
                "notes": null,
                "res": null,
                "res": null,
                "d": "H",
                "L": "1"
            },
            {
                "header": null,
                "subheader": null,
                "name": "- Project objective",
                "example": null,
                "notes": null,
                "res": "Contoso",
                "q": null,
                "h": null,
                "rev": "Short Description",
                "d": "D",
                "L": "3"
            },
            {
                "header": null,
                "subheader": null,
                "name": "- Work breakdown structure (WBS)",
                "example": null,
                "notes": null,
                "res": "Contoso",
                "q": null,
                "h": null,
                "rev": "x",
                "d": "D",
                "L": "3"
            }
        ]
    },
    {
        "name": "Electrical Engineering  ",
        "totalhours": " 65",
        "disciplinedescription": "",
        "s": [
            {
                "header": "General Electrical Engineering",
                "subheader": null,
                "name": null,
                "example": "null",
                "notes": null,
                "res": null,
                "res": null,
                "d": "H",
                "L": "0"
            },
            {
                "header": null,
                "subheader": null,
                "name": "Electrical engineering design criteria",
                "example": null,
                "notes": null,
                "res": "Contoso",
                "q": null,
                "h": null,
                "rev": "x",
                "d": "D",
                "L": "3"
            },
            {
                "header": null,
                "subheader": null,
                "name": "Electrical instructions",
                "example": null,
                "notes": null,
                "res": "Option",
                "q": null,
                "h": null,
                "rev": "x",
                "d": "D",
                "L": "3"
            }
        ]
    },
    {
        "name": "Civil and Structural",
        "totalhours": " 65",
        "disciplinedescription": "",
        "s": [
            {
                "header": "Civil and Structural",
                "subheader": null,
                "name": null,
                "example": "",
                "notes": null,
                "res": null,
                "res": null,
                "d": "H",
                "L": "0"
            },
            {
                "header": null,
                "subheader": null,
                "name": "Input to cost estimation",
                "example": null,
                "notes": "test notes",
                "res": "Contoso",
                "q": null,
                "h": null,
                "rev": "-50% / +50%",
                "d": "A",
                "L": "3"
            },
            {
                "header": null,
                "subheader": null,
                "name": "Input to layout design",
                "example": null,
                "notes": null,
                "res": "Contoso",
                "q": null,
                "h": null,
                "rev": "x",
                "d": "A",
                "L": "3"
            },
            {
                "header": null,
                "subheader": null,
                "name": "Building areas and volumes",
                "example": null,
                "notes": null,
                "res": "Contoso",
                "q": null,
                "h": null,
                "rev": "Preliminary",
                "d": "D",
                "L": "3"
            }
        ]
    }
]

Also I tried to change the quote in the query, it doesn't work

Hi @SnowBlue,

Please try to use this operator in the filter condition "=="

{{D = s|filter(value.d == "H" || value.d == "D")}}

I also check our example and the filter formatter worked correctly.

Best regards,
Petr
Plumsail team

1 Like

I find a workaround to realize what I want. Instead of filtering the row where d has "H" and "D" value, I use two hide-block-if to exclude the row where d has "A" and "I" value. Like below picuture. (the d attribute only has H, A, D, I value)

Thank you so much @Petr ! This works! I missed an extra "=" for the operator, so simple solution!

As for my case I have the header and subheader object missing the "rev", "q", and "h" attribute so it will print like blow for header and subheader rows. But it's the problem of my JSON. I need to improve my JSON. Or I will stick to the workaround I post above just now to use hide-block-if. With the hide-block-if, it doesn't care if I have missing attribute in the header and subheader object

1 Like