Skip to main content
sharmilan9331
Participating Frequently
Nov 18, 2024 8:57 AM UTC
Solved

Remove attributes with null values from a cdt

Hi, 

I have a requirement to remove attributes with null values from a cdt, so that downstream system can consume it properly. 

Given: {a:null, b: 10, c: "", d: 20}

Expected: {b: 10, d: 20}

Please let me know if there is an easy way to do this. 

    kumara0180
    Participating Frequently
    Nov 18, 2024 11:41 AM UTC

    a!fromJson(a!toJson({ a: null, b: 10, c: "", d: 20 }, true()))

    4 replies

    udhayak0001
    Inspiring
    Nov 18, 2024 9:56 AM UTC

    If you are sending this info In API ,you can use the below

    kumara0180
    Participating Frequently
    Nov 18, 2024 11:41 AM UTC

    a!fromJson(a!toJson({ a: null, b: 10, c: "", d: 20 }, true()))

    gayatria0439
    Participating Frequently
    Nov 19, 2024 9:59 AM UTC

    The toJson() function is used to remove null or empty values. When you set it to true, it will exclude or remove the null values from your array or data. After that, you can convert the Json data back to a standard dictionary format using the a!fromJson() function. Here am adding a snippet for your reference

    sarathkumr268295
    Known Participant
    Nov 19, 2024 11:09 AM UTC

    Inside the integration, there will be check box called "Remove fields with null or empty values from generated JSON". This will remove the null values from the JSON. This one can be used