JSON Schema: ensuring that all elements within an array are distinct and not null

I am currently in the process of developing a JSON schema that needs to meet the following criteria:

  1. The schema must declare a top-level object with at least one property
  2. Each property's value should be an array, with each array containing exactly N items
  3. Items within the arrays must be integers within the closed interval [J, K], or null
  4. Integer items within each array must be unique
  5. No uniqueness constraint should be applied to null (there should be no relationship between N and the interval size K-J)

While I have successfully satisfied the first 3 requirements and partially met the 4th using the following schema, I am facing challenges with points #4 and #5:

{
  "$schema": "http://json-schema.org/draft/2019-09/schema#",
  "type": "object",
  "minProperties": 1,
  "additionalProperties": {
    "type": "array",
    "minItems": N,
    "maxItems": N,
    "items": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": J,
          "maximum": K
        },
        {
          "type": "null"
        }
      ]
    },
    "uniqueItems": true
  }
}

I am seeking guidance on how to impose the uniqueItems constraint selectively on non-null items within the array. My initial attempts to move uniqueItems to different levels of the schema did not yield the desired results.

While exploring conditional possibilities, I have not yet determined if this approach will work. I am hopeful that there might be a simpler solution that I have overlooked.

Therefore, my query is: Is there a method to define a JSON schema array where uniqueness is enforced solely on non-null items?

Answer №1

This particular scenario is not within the scope of uniqueItems and is beyond the limitations of JSON Schema. It is advisable to address this stipulation in another part of your application's operational guidelines.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Extracting POST information through PHP's AJAX Request

I am facing an issue where I keep receiving null values when using the following code: Here is my Ajax request: formData = { u: "3959eeadb32e02b85a792e21c", id: "6d7613df26" }; $.ajax({ ...

Animate the leftward disappearance of a div to make it vanish

My goal is to create a user interface where users can navigate through different divs. Here is the HTML code: <article id="realize" class="realizeBox"> <div class="shown"> <div class="heading"> <h2>Realisati ...

php | wordpress | arrange values in an array

In my Wordpress project, I am working with a custom post type called "publications." Initially, each publication was assigned to a single category, and sorting them by category was a straightforward process... $args = array( 'post_type' => &a ...

Add a border to the navigation bar item to indicate the current page being displayed

This section shows the current navigation bar item https://i.sstatic.net/6RAGJ.png This is the desired outcome when clicking on the tab https://i.sstatic.net/8nFeB.png Uncertain about the best approach for achieving this. I have attempted to submit a val ...

The property fails to reflect changes in state

I am currently developing an application that requires fetching data asynchronously and preserving the state in the parent component while also passing the data reference to children components. I encountered an issue where the props do not update when the ...

PHP is unable to render Google Maps on the webpage

My PHP code retrieves location information from a database (test) and table named manu, created using phpmyadmin in Wamp. It then displays those locations on a map with markers, showing latitude and longitude values. UPDATED <? $dbname =&ap ...

Looking for assistance in setting up an auto-suggest feature that displays retrieved or matched data from the database in a list format

I am currently facing an issue with the following problem: I have a form that includes a single search field with autosuggest functionality. I want to be able to type either a name or mobile number in this field. As I type, suggestions should appear base ...

What is the best approach to structure a React project in which a component's rendering changes with each instance?

I am facing a challenge with rendering a component that relies on multiple AJAX calls to complete. These AJAX responses return different data each time, and I want to implement a button that will trigger the re-rendering of this random component every time ...

Adding styling to my project using @material-ui v5 has resulted in a CSS rule being injected, although I did not define it myself

I'm in the process of incorporating a simple menu component into my project, and I followed the instructions provided in the documentation. When viewing it in a CodeSandbox, everything appears as expected. However, within my actual project, the menu ...

Unlock the Power of EmailJS with Vue.js 2 and TypeScript

I couldn't find a similar issue online, so here's my problem. I'm trying to create a form for receiving contact from an app using Vue.js 2 and TypeScript. Here is my code: <form ref="form" class="form-data" @submit.pr ...

Harness the power of the ioHook Node.js global native keyboard and mouse listener within your Browser environment

I'm dealing with a challenging issue that seems to have no solution due to security limitations. However, I'm reaching out to you as my last hope to find a workaround. For my project, I require a system that can monitor user mouse and keyboard a ...

The THREE.LineSegments - geometry.updateNeeded isn't refreshing

Hello, I'm having trouble updating my THREE.LineSegments using geometry.needsUpdate. In my animation, I am drawing a square side by side in a clockwise motion with each iteration. Even though I can see that the values of the side array are changing co ...

Ways to manage a post request in Next.js

Attempting to establish a POST route within my api directory with next.js. After sending the data to the route, I am having difficulty parsing the data in order to properly store it in the database. What would be the most effective approach for managing ...

Arrange a multi-dimensional array first by its keys and then by its values

Looking to organize a two-dimensional array based on both keys and values. Here is the current array: Array ( [0] => Array ( [Transport] => imagem3.png ) [1] => Array ( [Transport] => ...

Android development often involves working with JSON deserialization, a process that can be made easier

Upon receiving an ArrayList of custom objects called MyList, which is a HashMap containing another ArrayList of custom objects called MyListElement (also HashMaps), the GSON serialization output appears as follows: { "list buyed list": [], ...

Transforming specific symbols (é è ë) with URL encoding

I am currently working on a JavaScript function that opens the user's email client with pre-filled content. However, I am facing difficulties in converting special characters so they display correctly in the email client (especially when passed throu ...

Having Trouble with Finding Visible Divs?

Below is the code snippet I am working with: var len = $(".per:visible").length; $("#add-person").click(function(){ if ($(".persons div:visible").next().is(':hidden')){ $(".persons div:visible").next().slideDown('slow' , ...

Eliminable Chips feature in the Material UI Multiple Select component

The Material UI documentation showcases a multiple select example where the selected options are displayed using the Chip component and the renderValue prop on the Select. By default, clicking on the current value opens the list of available options. I am ...

Instructions on changing the color and font weight of an asterisk within a Textfield using Material UI

Is there a way to style the asterisk in red and bold within a Textfield using material UI? I have a placeholder text without a label, as my label is null or empty. I would like to make the placeholder star RED. Is this possible? Here is the code snippet: h ...

Add a new sibling item to Angular-UI-tree

I am trying to add a sibling item to a tree when clicked in angular-ui-tree (https://github.com/angular-ui-tree/angular-ui-tree) Here is an example of what I currently have: <item><input value"item A #1"><button>insert under</button& ...