The mismatch between JSON schema validation for patternProperties and properties causes confusion

Here is the JSON schema I am working with:

{
  "title": "JSON Schema for magazine subscription",
  "type": "object",
  "properties": {
    "lab": {
      "type": "string"
    }
  },
  "patternProperties": {
    "[A-Za-z][A-Za-z_]*[A-Za-z]": {
      "type": "boolean"
    }
  },
  "required": [
    "lab"
  ]
}

I am trying to match a JSON data like this:

{
 "SP": false,
 "lab": "labri"
}

However, it failed because the value of "lab" should be a boolean according to the schema. This means that "lab" matches the patternProperties.

Does anyone have a solution for this?

PS: Sorry for my English skills

Answer №1

To avoid matching 'lab' using regexp, one method is to craft a specific pattern that captures what you are looking for without also including 'lab'. This can be quite challenging.

Alternatively, consider implementing the following JSON schema:

{
    "title" : "JSON Schema for magazine subscriptions",
    "type" : "object",
    "properties" : {
        "magazine" : { "type" : "string" }
    },
    "additionalProperties" : { "type": "boolean" },
    "required" : [ "magazine" ]
}

This schema ensures that all properties except 'magazine' must be boolean values. It may not be easy to improve upon this solution.

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

PHP is unable to retrieve the formData object sent via ajax

I've been experimenting with sending a formData object to PHP (I'm following a tutorial at this link), but I'm encountering some obstacles. Firstly, I create the formData object and fill it with: var formdata = new FormData(); formdata.appe ...

How to add an item to an array in JavaScript without specifying a key

Is there a way to push an object into a JavaScript array without adding extra keys like 0, 1, 2, etc.? Currently, when I push my object into the array, it automatically adds these numeric keys. Below is the code snippet that I have tried: let newArr = []; ...

Update the database with the information provided by this model using Ajax technology

There is an Ajax function in my View that I am having trouble with. function Save() { var Url = '@Url.Action("UpdateCaseDetails", "CaseDetailView")'; var frm = $("form"); var data = JSON.stringify(frm.serializeArray()); $.ajax({ ...

Setting up Geolocation

I have been utilizing an APM tool for my work. The tool currently requires a pop-up in order to capture the user's location. However, there is now a need to capture the user's location without the pop-up appearing. Is there a method or workaroun ...

What is preventing the data property from updating in setInterval?

Looking for a way to increase the speed of the props while my marker is moving? Currently, the speed only updates when the pause button is clicked. How can I automatically update this.speed when clicking the speed button? I have defined the speed prop in ...

Using Flask for the frontend and integrating Tensorflow, however not utilizing Tensorflow serving

I currently have a straightforward 3-layer MLP model in Tensorflow designed to predict a single numerical output based on a 10-value input vector. My web application runs on the Flask framework, allowing clients to send a new 10-value input vector every m ...

The JWT Cookie has successfully surfaced within the application tab and is now being transmitted in the request

When sending a JWT token to an authorized user in Express, the following code is used: The cookie-parser module is utilized. module.exports.getUser = async (req, res, next) => { console.log('i am in getuser'); const { SIT } = req.query; ...

Tips on getting the dropdown value to show up on the header when it changes using Angular 2 and TypeScript

I need assistance with creating a dropdown field in Angular2. When the user selects "car", I want it to display beside the heading. Can anyone provide guidance on how to achieve this? HTML: <h1>Heading <span *ngFor= "let apps of apps">({{apps ...

Upon initiating a fresh project with npm create vite@latest and proceeding with npm install, an error message promptly surfaces

semver <7.5.2 Severity: moderate Potential vulnerability in semver due to Regular Expression Denial of Service - https://github.com/advisories/GHSA-c2qf-rxjj-qqgw A fix is available by using the command npm audit fix --force Running this may install [e ...

Creating Dynamic Height for Div Based on Another Element's Height Using ReactJS and CSS

I'm attempting to set a fixed height for a div in order to enable overflow scrolling. However, I am encountering issues as I am using JavaScript within a useEffect hook to accomplish this task. The problem is inconsistent as sometimes the height is se ...

What is the best way to modify the size of a canvas element while maintaining effectiveness?

I've encountered an issue while using Canvas to create a pie chart with chart.js. Despite adjusting the dimensions of the canvas element, it continues to take up the entire page. <canvas id="myChart" height ="200" width="200"></can ...

Error in Firebase Cloud Function: Function did not return the expected Promise or value and instead returned undefined

I've been encountering an issue with my cloud function that triggers on specific database writes (onCreate). It seems to be working fine, but I keep getting an error message stating "Function returned undefined, expected Promise or value" even though ...

Transform a flat 2D shape into a dynamic 3D projection using d3.js, then customize the height based on the specific value from ANG

Currently, I am utilizing d3.js version 6 to generate a 3D representation of the 2D chart shown below. Within this circle are numerous squares, each colored based on its assigned value. The intensity of the color increases with higher values. My goal is t ...

A comprehensive guide to understanding the nested structure in Elasticsearch mappings

I need advice on how to effectively map a dynamic structure for Elasticsearch consumption. The json raw data has a variable portion within the structure instead of static outer elements. For example, here is a snippet of the json: "stat": { "state": ...

The backend post request is returning only "undefined" in JavaScript

Hey there, I'm still learning JS so please bear with me. I've been working on incrementing a value in a JSON file within my JS backend app. However, whenever I try to increase the associated value by the key, it ends up creating a new section la ...

Guide on storing a JSON array in a MySQL database using Node.js and Express

I am currently setting up a MySQL database and I have a task of inserting approximately 1000 records that are organized in a JSON array Here is the JSON array that needs to be imported: [ { "DESCRIPTION": "انفرتر 1 حصان ...

What is the best way to handle multi-dimensional JSON data without keys in JavaScript?

My JSON data is structured as follows: { "bitcoin": [ "-0.47", "-0.46", "-0.42" ], "maker": [ "8.29", "8.29", "6.89" ] } I want to extract values from this data where keys are not specified. How can I achieve this? Update: Tha ...

Creating personalized serialization for bson and JSON in Golang using mgo libraries

I am working with a custom type in Golang called Base64Data: type Base64Data []byte To facilitate unmarshalling a base64 encoded string into this type, I implemented the following method: func (b *Base64Data) UnmarshalJSON(data []byte) error { if le ...

Guide to profiling resources in Node.js applications

When developing Node.js applications, it's important to keep track of how your code is performing in terms of memory and IO. By monitoring these metrics, you can identify which parts of your code are causing delays or consuming excessive resources. Th ...

What's the best way to group rows in an angular mat-table?

I am working on a detailed mat-table with expanded rows and trying to group the rows based on Execution Date. While looking at this Stackblitz example where the data is grouped alphabetically, I am struggling to understand where to place the group header c ...