cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace the fields having "NULL" and write as Blank I.E " "

Manzoor
New Contributor

Hi team,

 

There are few fields where I'm having value as NULL, I want to make NULL in to blank,  in all the Fields where I have the NULL. Help me in a way so that I can write a logic which can replace all the NULL in to Blank.

Thanks in Advance.

1 ACCEPTED SOLUTION

j_angelevski
Contributor III

Hi @Manzoor ,

Depending on your input data, if you have a flat object, you can make all of the NULL fields blank by using the following expression:

$.mapValues(val => val == null ? "" : val)

This will iterate over each value for each key in the input data and depending if the value is null, it will return an empty string otherwise it will return the original value.

 

Input data sample:

[
    {
        "msg": "Hello, World",
        "num": 1,
        "field2": null
    }
]

 

Output:

[
  {
    "msg": "Hello, World",
    "num": 1,
    "field2": ""
  }
]

View solution in original post

2 REPLIES 2

j_angelevski
Contributor III

Hi @Manzoor ,

Depending on your input data, if you have a flat object, you can make all of the NULL fields blank by using the following expression:

$.mapValues(val => val == null ? "" : val)

This will iterate over each value for each key in the input data and depending if the value is null, it will return an empty string otherwise it will return the original value.

 

Input data sample:

[
    {
        "msg": "Hello, World",
        "num": 1,
        "field2": null
    }
]

 

Output:

[
  {
    "msg": "Hello, World",
    "num": 1,
    "field2": ""
  }
]

Thanks @j_angelevski