Json validation with unevaluatedProperties
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 57
- Joined: Tue Jul 21, 2009 1:48 am
Json validation with unevaluatedProperties
Hi, I'm trying to create test instances for JSON schemas that specify either "unevaluatedProperties" or "additionalProperties" as false. When I attach a schema to the JSON instance being used to test the schemas, I get an error because the "$schema" property used to attach the schema is considered additional/unevaluated.
I'm sure you have run into this already - just wondering if there is any way around it - it seems a perfectly reasonable error, but one that is frustrating as well - I have many smaller schemas that build into a larger one, and I don't want to implement a validation scenario for every single one - my preference is to attach the schema to the instance.
Thanks, Scott
I'm sure you have run into this already - just wondering if there is any way around it - it seems a perfectly reasonable error, but one that is frustrating as well - I have many smaller schemas that build into a larger one, and I don't want to implement a validation scenario for every single one - my preference is to attach the schema to the instance.
Thanks, Scott
-
- Posts: 38
- Joined: Wed Sep 09, 2020 3:17 pm
Re: Json validation with unevaluatedProperties
Post by florin_nica »
Hi Scott,
I understand that this behavior can be frustrating when working with multiple schemas. I suggest adding in each schema, rather than using the boolean version This way, you can explicitly allow the $schema property, which will help bypass the validation error.
Regards,
Florin
I understand that this behavior can be frustrating when working with multiple schemas. I suggest adding
Code: Select all
"unevaluatedProperties": {"$schema": true}
Code: Select all
"unevaluatedProperties": true
Regards,
Florin
-
- Posts: 57
- Joined: Tue Jul 21, 2009 1:48 am
Re: Json validation with unevaluatedProperties
Actually... revisiting this, I don't think your suggestion works - I think it just sets unevaluatedProperties to "true" as it will allow $schema, but it also allows everything else. Thought I'd point this out since I saw this thread coming up in some AI results and I think folks should know it's not valid. For example, this schema:
will validate this (rather than flagging "foo" and not flagging $schema):
Not sure there is a way around this without just adding "$schema" as a property to your schemas, or Oxygen (and other validating editors) providing some software work-around.
Code: Select all
{
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"type": "object",
"properties": {
"propertyName": {
"type": "string"
}
},
"unevaluatedProperties": {"$schema": true}
}
Code: Select all
{
"$schema": "test.jschema",
"propertyName": "propertyName",
"foo": "bar"
}
-
- Posts: 38
- Joined: Wed Sep 09, 2020 3:17 pm
Re: Json validation with unevaluatedProperties
Post by florin_nica »
Hi, Scott,
You are correct, the proposed solution doesn't appear to be suitable. A potential workaround could involve using the patternProperties keyword to explicitly allow only the $schema property, as shown below:
Let me know if this approach works for you.
Regards,
Florin
You are correct, the proposed solution doesn't appear to be suitable. A potential workaround could involve using the patternProperties keyword to explicitly allow only the $schema property, as shown below:
Code: Select all
{
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"type": "object",
"properties": {
"propertyName": {
"type": "string"
}
},
"patternProperties": {
"^\\$schema$": {"type": "string"}
},
"unevaluatedProperties": false
}
Regards,
Florin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service