question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Are there any way to filter out nulls from result?

See original GitHub issue

Hello, I have the following JSLT file:

{
  "formId": "Company",
  "fieldValues":
    [
        {
            "name": "CompanyName",
            "value": {
                "en_US": string(.data.companyName)
            }
        },
        if (contains("Android", array(.data.platforms)))
        {
            "name": "PlatformAndroid",
            "value": {
                "en_US": true
            }
        },
        if (contains("IOS", array(.data.platforms)))
        {
            "name": "PlatformIOS",
            "value": {
                "en_US": true
            }
        },
        if (contains("MicrosoftStore", array(.data.platforms)))
        {
            "name": "PlatformMicrosoftStore",
            "value": {
                "en_US": true
            }
        },
        {
            "name": "Pack",
            "value": {
                "en_US": string(.data.pack)
            }
        }
    ]
}

But the fieldValues array contains nulls if there are no platforms checked because of the behavior of if statement.

Before this solution, I tried to iterate over .data.platforms but I couldn’t because in this case the result will be a separated array. After that I tried to define a new function for that, but I couldn’t.

Do you have any idea? Thank you.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16

github_iconTop GitHub Comments

2reactions
shark300commented, Aug 3, 2021

Thank you Guys, you are great! I’m testing all approaches as well.

2reactions
contatolucascostacommented, Aug 3, 2021

Hi @shark300

Follow the solution. Basically you transform all content in a array, then you print (with loop “for”) the elements != null

Jslt:

{ “formId”: “Company”, “fieldValues”: [for(array( [ { “name”: “CompanyName”, “value”: { “en_US”: string(.data.companyName) } }, if (contains(“Android”, array(.data.platforms))) { “name”: “PlatformAndroid”, “value”: { “en_US”: true } }, if (contains(“IOS”, array(.data.platforms))) { “name”: “PlatformIOS”, “value”: { “en_US”: true } }, if (contains(“MicrosoftStore”, array(.data.platforms))) { “name”: “PlatformMicrosoftStore”, “value”: { “en_US”: true } }, { “name”: “Pack”, “value”: { “en_US”: string(.data.pack) } } ] )). if( . != null)] }

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to filter out null values - sql - Stack Overflow
The results of my SQL query include null values. How do I filter out null values? ... Please add a few rows of...
Read more >
How to SELECT Records With No NULL Values in MySQL
There you have it; a simple comparison operator that can be used to filter out any and all NULL values in your records....
Read more >
How to hide null values from a Tableau filter - TAR Solutions
1. Create a set on the Dimension containing the filter values. · 2. Exclude the Null (or other unwanted values) from the set...
Read more >
How to Filter Rows without NULL in a column | LearnSQL.com
To display records without NULL in a column, use the operator IS NOT NULL. You only need the name of the column (or...
Read more >
Spark Filter Rows with NULL Values in DataFrame
In many cases NULL on columns needs to handles before you performing any operations on columns as operations on NULL values results in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found