Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validating unique key values in array of objects #79

Open
jksull opened this issue Mar 25, 2024 · 0 comments
Open

validating unique key values in array of objects #79

jksull opened this issue Mar 25, 2024 · 0 comments

Comments

@jksull
Copy link

jksull commented Mar 25, 2024

Firstly I'd like to thank you for this incredibly useful wrapper!

I apologise if the answer to my question should be clear, and whether my use of terminology is mispalced. I am very new to JSON schema and validation of json structures within R, and despite attempting to find the answer within the documentation of jsonvalidate, ajv, and JSON Schema, it's still not completely clear if what I am looking to do is possible with this libary.

I am wondering if there is a way to validate that the values of keys for an array of objects are unique.

This problem has been well-discussed previously here: Key-based item uniqueness

For example, given the schema:

{
  "type" : "array",
  "items" : {
    "type" : "object",
    "properties" : {
      "foo" : { "type" : "integer" },
      "bar" : { "type" : "string" }
    }
  },
  "uniqueItems" : true
}

The instance:

[ { "foo" : 1, "bar" : "value1" }, { "foo" : 1, "bar" : "value2" } ]

Currently passes as there is no vocabulary(?) for validating that a value is repeated in the given data.

In my efforts to find a way to do this, I came across two possible options generally speaking:

Firstly, by defining a custom keyword for ajv, as described here: https://ajv.js.org/packages/ajv-keywords.html#uniqueitemproperties

Is it possible to define keywords to be used by the ajv engine when using jsonvalidate?

Another solution I found was resulting from the Key-based item uniqueness discussion I mentioned earlier. Using a meta-schema "vocabulary" extending the validation of arrays.

Is it possible to extend the vocabulary of the 'legal' draft schema within jsonvalidate?

Again I apologise if this should be clear that it is beyond the intention of this library, but I wanted to clarify these questions before resolving this situation using other means!

Thank you in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant