0

How to handle missing node in nested json

I have the below JSON and I just wanted to use a table to display 2 columns 
name, date

{
    "issues": [{
            "name": "Issue 1",
            "release": [{
                "version": "1",
                "date": "2022-01-01"
            }]
        },
        {
            "name": "Issue 2",
            "release": [{
                "version": "2"
            }]
        },
        {
            "name": "Issue 3",
            "release": [{
                "version": "3",
                "date": "2022-01-02"
            }]
        }

    ]
}

The "date" in the second item is missing, so the data is not aligned, tried to use @kf:fill_elements(/issues/releases,'date') doesn't work as far as I know because of nested array, how can I achieve this request? 

Thank you.

2 comments

  • Avatar
    Kalyani Official comment

    Hi Vinh, 

    If you remove the extra 's' from the releases in the XPath, the kf:fill_elements should work. 

    @kf:fill_elements(/issues/release,'date') 

     

    Cheers! 

  • 0
    Avatar
    Vinh Lam

    Kalyani, my mistake about the "s". I confirm it works with the above sample

    However, I just double-check my real data, the second item is just like this

     {
                "name": "Issue 2",
                "release": []
            },

     

    it's an empty array, how can I fill the empty value in this case?

     

    it's totally empty array

Please sign in to leave a comment.