Sometimes it happens that we receive an object, but not all the properties have been defined, and the flow fails and throws an error because the property does not exist.
Since we know what properties we are going to use in the flow, what we have to do is create an object with all properties null and then perform a union of the two objects.
First I created a flow, in this case the trigger is manual, then I initialize two string variables:
The first is the string of the json object with all properties set to null
In this example an object is defined with three properties: year, month, day
{"year":null,"month":null,"day":null}

The second is the string of the json object that has arrived, in this case simulated that one of the three properties is missing
{"year":2022,"month":12}

Then I parse the two json strings to get the two objects



Finally I define using Compose the union of the two objects with all the properties
union(body('Parse_JSON_Property'),body('Parse_JSON_String'))

The result as you can see is the object complete with all properties and with all values, and for missing properties it will be assigned null values

If you have nested objects, the child properties will not be automatically merged
In this example I added the time property with an object with three other child properties
{"year":null,"month":null,"day":null,"time":{"hour":null,"minute":null,"second":null}}
and I simulate that the object that arrived has no main properties and no child properties

After doing the parse of the two string variables (see above)
I perform the union of the child properties separately from the main ones
union(body('Parse_JSON_Property')['time'],body('Parse_JSON_String')['time'])


As you can see merging two objects fails to merge the child properties

So we need to set the property with children
setProperty(outputs('Union_JSON_Property_'), 'time', outputs('Union_JSON_Child_Property'))

