What is the proper method for utilizing the "oneOf" keyword in this schema?

Is it possible to have either option A or B, but not both (mutually exclusive)?

In Draft 3, I am required to use whatever is available, even though the version on top says 4. This is because when using an array for "required", it throws an error stating that it cannot convert an array to a boolean. If arrays are removed without specifying the use of draft 4, Newtonsoft.Json.Schema.Extensions::IsValid does not validate properly and returns "true" randomly.

Unfortunately, I must utilize an outdated version of Newtonsoft.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "SearchCriteria": {
      "type": "array",
      "uniqueItems": true,
      "minItems": 1,
      "required": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "A": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[^\\s]*$"
          },
          "B": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "pattern": "^[^\\s]*$",
              "enum": ["One", "Two"]
            },
            "minItems": 1
          },
          "C": {
            "type": "string",
            "required": true,
            "minLength": 2
          },
          "D": {
            "type": "array",
            "required": true,
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
          }
        }
      }
    }
  }
}

Answer №1

Draft 3 does not have support for OneOf or similar features, as pointed out in a comment by @dbc.

[Newtonsoft.Json.Schema.JsonSchema]
utilizes draft 3 to interpret the JSON file. This is why it was disregarding OneOf and generating an error for "required" being presented as an array. In draft 3, "required" can only be a boolean.

To address this issue, utilize [Newtonsoft.Json.Schema.JSchema] to decode the Schema as a string, [Newtonsoft.Json.Linq.JToken] to decode the JSON as a string, and

[Newtonsoft.Json.Schema.SchemaExtensions]
to validate instead of using
[Newtonsoft.Json.Schema.Extensions]
.

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

Understanding how to retrieve the FileType from a Document Object Model using JavaScript

Looking at this DOM structure, we have an image with the following details: <img id="this-is-the-image" src="http://192.168.1.100/Image_tmp/2016-06/d4eb8d"> The task at hand is to click a button, execute a JavaScript function, and download the ima ...

Remove the JSON object by comparing IDs between two JSON objects in JavaScript or Node.js, deleting it if the ID is not found

let data = fetchData(); let anotherData = getAnotherData(); let result = data.reduce((accumulator, current) => { if (!accumulator[current.system.name]) { accumulator[current.system.name] = {}; } let detailsObject = {}; Object.keys(current. ...

What is the best way to adjust the spacing between components to prevent overlapping?

I'm looking to adjust the spacing between the textfield and button components so they don't overlap. I want to create some space between them but I'm not sure how to achieve this. I'd like to have at least 1-2 spaces added between the ...

Timer repeatedly triggered until nausea ensued (native v8natives.js:1582)

My website is running extremely slow and after conducting a test using the Timeline feature in Chrome Tools for Developers, I discovered that there is a Timer firing in a JS file called v8natives.js for about 9 seconds. After checking my Wordpress plugins, ...

Creating a Python API for JSON data reading

Update for 2020: Unfortunately, the API is currently not functioning properly and is no longer accessible. I am trying to utilize a JSON api in order to retrieve a random color and store it in a variable. Here's the code I have attempted so far: The ...

Unable to utilize a third setState function due to the error message indicating an excessive number of re-renders

My current challenge involves setting an initial state for my Hook. I have a clickable element that changes the state between Decreasing and Increasing upon click, and this part is functioning properly. However, I encounter an issue when attempting to defi ...

Utilizing jq to iterate through JSON and perform replacements

UPDATE: After reassessing my initial question, I have found that I can extract all the necessary data in one API call. The JSON response from my API call is as follows: { "lights": { "8": { "name": &qu ...

Receiving a Javascript Callback from Paypal

Is it possible to receive a JavaScript callback after a successful PayPal purchase made using a button? I am aware of IPN, but it requires a return URL. My main goal is to simply determine if a user has completed a purchase with the button. ...

Sending JSON data from SignalR back to Knockout ViewModel

I'm struggling with my Knockout and SignalR implementation as a beginner. Although I can display JSON data in a debug element by databinding it to dashboard, I encounter undefined errors when trying more complex databinding. For example, the code sni ...

Issues are arising with the .mouseover functionality within this particular code snippet

Learning Javascript has been a challenge for me so far. I tried following a tutorial, but the result I got wasn't what I expected based on the video. I'm wondering why that is and how I can fix it. I'm aiming to make a box appear suddenly w ...

Managing backslashes within json strings in PHP is a common challenge that many developers face

It seems like there is a strange issue occurring with json_encode and/or json_decode when trying to decode a string that was generated by json_encode: $object = new stdClass; $object->namespace = 'myCompany\package\subpackage&apo ...

Encountered an issue while attempting to retrieve the access token from Azure using JavaScript, as the response data could

Seeking an Access token for my registered application on Azure, I decided to write some code to interact with the REST API. Here is the code snippet: <html> <head> <title>Test</title> <script src="https://ajax.google ...

Preventing AngularJS from Binding in Rows: A Solution

Currently, I am utilizing AngularJS version 1.5.3 and I am facing an issue with my services. I have two services - one that retrieves Area names and the other that fetches details for each Area. In my code, I first call the service to get the Area names an ...

Learn how to eliminate all text characters from a string using jQuery, leaving only the numerical values behind

My webpage features a variety of different products, each with their own values. When trying to calculate the total sum of these products and display it in the shopping cart, I encountered an error displaying NaN. How can I remove this NaN from the strin ...

Issue with Angular dropdown menu not showing the initial option

I am trying to set up a drop-down menu with the first item in the list appearing after it has been sorted by 'name' using the code snippet below: <h2 class="presentation site is-input-header">Site</h2> <div class="modal-select-ele ...

Utilizing HTML injection to access both the Chrome API and global variables

I am currently developing a new Chrome Extension and am diving into the process for the first time. My extension involves injecting an HTML sidebar into web pages, adding JavaScript functions to the header, and allowing users to interact with buttons on th ...

Using "jq" to properly format multi-line text for escaping purposes

Let's say I have a multi-line text that needs to be escaped: printf "\"aaa\"\nbbb" "aaa" bbb I'm attempting to escape it using the command jq -aR: printf "\"aaa\"\nbbb"| jq -aR "\"aaa\"" "bbb" ...

The target element is out of reach for the Puppeteer selector

When trying to extract the source of multiple images, I encountered an issue with the selectors not working properly. It seems like the elements are fake or not actually present on the page. Every page contains one of the desired elements (the main image) ...

Dealing with issues of toggling visibility with jQuery when using a dropdown menu

Inside a hidden drop down div, the focus is on "DC" right now. In the image below, we are looking at sales: HTML: <td class="edit"> <select class="touch" style="display: none;"> <option value="11">Rebuying</option><option value ...

Validate if the data is null or empty in a JSON

If I received an empty JSON response, I would handle it like this: $.ajax ({ type : 'POST', url : get.php, dataType: 'json', success : function(data) { console.log(data.length); } }); GET.PHP $query ...