cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
iso
Advocate I
Advocate I

ParseJSON action does not accept valid null value as allowed by JSON schema spec

I am writing this post (issue definition + solution down below) in case others run into the same issue with ParseJSON handling of null value as perusing this forum returned no post that clearly addresses the following issue:

 

[
  {
    "message": "Invalid type. Expected Number but got Null.",
    "lineNumber": 0,
    "linePosition": 0,
    "path": "min",
    "schemaId": "#/properties/min",
    "errorType": "type",
    "childErrors": []
  },
  {
    "message": "Invalid type. Expected Number but got Null.",
    "lineNumber": 0,
    "linePosition": 0,
    "path": "value",
    "schemaId": "#/properties/value",
    "errorType": "type",
    "childErrors": []
  },
  {
    "message": "Invalid type. Expected Number but got Null.",
    "lineNumber": 0,
    "linePosition": 0,
    "path": "max",
    "schemaId": "#/properties/max",
    "errorType": "type",
    "childErrors": []
  }
]

 

My mistake was to define the JSON schema like so:

 

{
    "type": "object",
    "properties": {
        "date_time": {
            "type": "string"
        },
        "type": {
            "type": "string"
        },
        "sensorID": {
            "type": "string"
        },
        "min": {
            "type": "number"
        },
        "value": {
            "type": "number"
        },
        "max": {
            "type": "number"
        }
    }
}

 

when instead it should have been:

 

{
    "type": "object",
    "properties": {
        "date_time": {
            "type": ["string", "null"]
        },
        "type": {
            "type": ["string", "null"]
        },
        "sensorID": {
            "type": ["string", "null"]
        },
        "min": {
            "type": ["number", "null"]
        },
        "value": {
            "type": ["number", "null"]
        },
        "max": {
            "type": ["number", "null"]
        }
    }
}

 

Now, just to make sure we are all on the same page when it comes to the allowed data type values in a JSON object, as mentioned on this site (and others) https://www.w3schools.com/js/js_json_datatypes.asp, 

 

"Values in JSON can be null.

Example

{ "middlename":null }"

 

and on this site: https://tools.ietf.org/html/draft-handrews-json-schema-02#page-9

 

7.6.1.  Assertions and Instance Primitive Types

   Most assertions only constrain values within a certain primitive
   type.  When the type of the instance is not of the type targeted by
   the keyword, the instance is considered to conform to the assertion.

   For example, the "maxLength" keyword from the companion validation
   vocabulary [json-schema-validation]: will only restrict certain
   strings (that are too long) from being valid.  If the instance is a
   number, boolean, null, array, or object, then it is valid against
   this assertion.

   This behavior allows keywords to be used more easily with instances
   that can be of multiple primitive types.  The companion validation
   vocabulary also includes a "type" keyword which can independently
   restrict the instance to one or more primitive types.  This allows
   for a concise expression of use cases such as a function that might
   return either a string of a certain length or a null value:


   {
       "type": ["string", "null"],
       "maxLength": 255
   }

 

Changing the schema definition as shown above solved the issue and ParseJSON action stopped issuing an error when one or more of my JSON properties/fields were set to null by the flow logic.

 

So there you have it--hope this will help keep the frustration level low 😉 

0 REPLIES 0

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (3,224)