cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
saadu
Microsoft
Microsoft

parse JSON: Ignoring null value's when parsing JSON payload

All,

 

Question:

What are my options to make sure my 'parse JSON'  ignores/accepts null values when parsing JSON payload from a Http Response.  Are there alternate options to extract json elements for my scenario ?

 

 

Context:

---------

I am buidling flow to send out email based on contents of http JSON response. JSON response will have attributes with value as null.  Parse JSON is throwing error message  "message": "Invalid type. Expected Object but got Null." I do not use the json attributes with null values in the flow and ok to loose it.

 

 

schema

----------

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "A": {
        "type": "string"
      },
      "B: {
        "type": "string"
      },
      "C": {
        "type": "string"
      },
      "D": {
        "type": "object"
      },
      "E": {
        "type": "string"
      },
      "F": {
        "type": "string"
      },
      "G": {
        "type": "string"
      },
      "H": {
        "type": "string"
      }
    },
    "required": [
      "A",
      "B",
      "C",
      "D",
      "E",
      "F",
      "G"
    
    ]
  }
}

 

 

 

JSON Payload

-------------------

{
      "A": "dfd",
      "B": "ASFS",
      "C": "asfs",
      "D": null,
      "E": "asFF",
      "F": "3244231",
      "D": "43124",
      "G": "qwqdas",
      "H": "zxz"
 }
     

 

 

 

Error Message

 

"message": "Invalid type. Expected Object but got Null."
   

 

 

10 REPLIES 10
v-micsh-msft
Community Support
Community Support

Hi @saadu,

 

I could confirm that the NULL value can't be recognized by Microsoft Flow, at least currently.

Syntax for GetRows

The empty function under Workflow Definition Language would work with the NULL value, but for other functions, not working.

I will forward this from my side, hope there should be some workarounds for this.

Regards,

Michael

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-micsh-msft
Community Support
Community Support

Hi @saadu,

 

Update here for the NULL value in WDL:
Quoted from Staff Samuel

"

Yes, technically the null operator ('?') and/or coalesce() function would work, but they require some hand-crafting if being used in the current Flow editor UI.

 

The workaround is that you can write a raw logicapp expression as long as it evaluates to a string. So for the possibly-null field, instead of using the automatic "Description" token in the UI, you'd write something like:

 

    Desc: @{coalesce(triggerBody()['description'], 'default description text')}

 

The caveats for falling back to a raw logicapp expresion:

    1. Must evaluate to a string

    2. Must have a string or character before the @ sign

    3. The field will become read-only after the initial save.

"

Reference: Is there a way to process null values from CRM to SharePoint.

Hope the information above is helpful.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-micsh-msft,

 

Can you elaborate on this a little further? Are we using the operator within the Parse JSON function?

Ben_Love
Advocate IV
Advocate IV

I recently had a similar challenge. My solution was to allow NULL values through my JSON Schema. In this way any NULL values passed did not cause error. 

 

EG:

 

"CompanyName": {
"type": [
"string",
"null"
]
}

Thanks @Ben_Love, very useful!

LOVE YOU, BEN! This really helped, thanks! 🙂 

Thank you

virakones
Responsive Resident
Responsive Resident

@Ben_Love 

Thank you!! Super helpful. 

TheSaj
Frequent Visitor

Thank you Ben, this resolved my import issue.

Does anyone have a simple strategy/implementation for when importing data into a list to handle whether:
Record already exists
a) update if record has changed
b) skip if no change

Got link to point me in the right direction?

Does your new record contain any unique information like a record ID? You could try finding the item in the list before inserting. I'm assuming you mean SharePoint lists. This might help: Retrieving Single Item from SharePoint List in Microsoft Flow

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,779)