Hi all, I am using a Validate Payload node to validate the input to a workflow. JSONSchema has a default parameter for properties, to set a default value, but it doesn’t seem this is implemented in Losant. If I require a field, and add a default value, it just fails to validate if the field isn’t present, and if I add a default value but don’t make it required, it the default value doesn’t get added. Is this correct?
Hey @Dolf_Andringa,
There’s a couple of things going on, which certainly makes this confusing.
You’ve linked what appears to be a different JSON-schema implementation that treats default
differently. That implementation says the default
value is used for validation if no value is present.
The implementation we use treats default
as an annotation - it’s there to act as an example for non-validation uses of the schema.
In both cases, the default
value is never added to your data.
Hi @Brandon_Cannaday
You are absolutely right. I just checked the official docs JSON Schema Validation: A Vocabulary for Structural Validation of JSON
and indeed default
is listed under “Basic Meta-Data Annotations” described as
These general-purpose annotation keywords provide commonly used information for documentation and user interface display purposes.
Its not intuitive to me in json-schema that you shouldn’t expect the default
to actually have an effect, but that seems to be what was intended. Just documentation. So your implementation seems to be correct.