How to ignore node null in json in Pentaho

221 views Asked by At

I have a json like this:

{
    users:[
    {
        name: 'Jonh Smith'
        address: {
            province: 'Thanh Hoa',
            district: 'Tp Dong Son',
            ward: 'Dien Bien',
            raw_address: 'No 14'
        }
    },  
    {
        name: 'Taylor Sweet'
        address: {
            province: 'Thanh Hoa',
            district: 'Tp Dong Son',
            ward: 'Dien Bien',
            raw_address: 'No 14'
        }
    },
    {
        name: 'Athlee Bans'
        address: null
    }]
}

I used Json Input in Pentaho to get data. [![enter image description here][1]][1]

But you can see, Athlee Bans's address is null. So when get data, I meet an error:

The data structure is not the same inside the resource! We found 1 values for json path [$.users[*].address.province], which is different that the number returned for path [$.users[*].name] (3 values). We MUST have the same number of values for all paths.

I have cheked ignore missing path on Content Tab: [![enter image description here][2]][2]

So how to ignore this error and have full data? Thanks! [1]: https://i.stack.imgur.com/bjbIw.png [2]: https://i.stack.imgur.com/VmlLr.png

1

There are 1 answers

0
Bert-Jan Stroop On

You normally handle this by running it in 2 consecutive json steps instead of in 1. First run the json step and retrieve address as a whole element, instead of grabbing immediatly the seperate fields, and then in the next step run the jsonstep just for the addres field, which will then only run if it is not null.

After cleaning up, your json (double quotes and commas) should look like this:

{
  "users": [
    {
      "name": "Jonh Smith",
      "address": {
        "province": "Thanh Hoa",
        "district": "Tp Dong Son",
        "ward": "Dien Bien",
        "raw_address": "No 14"
      }
    },
    {
      "name": "Taylor Sweet",
      "address": {
        "province": "Thanh Hoa",
        "district": "Tp Dong Son",
        "ward": "Dien Bien",
        "raw_address": "No 14"
      }
    },
    {
      "name": "Athlee Bans",
      "address": null
    }
  ]
}

The flow should then look like this:

Double JSON flow