Skip to content

validating unique key values in array of objects #79

@jksull

Description

@jksull

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions