Ways to authenticate custom kinds in JSON schema?

When working with JSON Schema, one of the challenges I have faced is the limitation on supporting ‘double’ and ‘float’ types for numeric values. While using AJV in JavaScript to validate a schema, it fails due to this restriction. Is there a way to specifically validate these double and float types?

It should be noted that my goal is to validate two main things - 1. The JSON schema itself 2. The JSON data against the defined schema

However, I am currently experiencing difficulties with the first step.

I have attempted to add a custom keyword in AJV, but it doesn't quite match up with the default type validation process.

For instance, my schema includes:

"lineSpacing": {
          "type": "double",
          "description": "Spacing between two lines"
        },

The AJV compilation does not seem to accept ‘double’ as a valid type. How can this issue be resolved? Am I overlooking a very basic concept? Any alternative solutions or suggestions in other programming languages would also be appreciated.

Answer №1

Initially, I was confused about the need to define "double" in your schema. In JSON schema, the type "number" allows you to specify decimal, positive, or negative values. For example:

1.20     // valid
-1      // valid
200    // valid 
"42"  // invalid, as it is enclosed in double quotes which means it's a string

Answer №2

Utilizing a personalized format for the pre-existing number data type is a highly recommended approach within JSON Schema configuration. Certain validator systems have the capability to accommodate custom value options for the format parameter, extending beyond just the string data type.

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

typescript: define the type of an object that behaves like a map

My current approach involves utilizing an object to store a map, where keys are strings and values are of a fixed type T. Upon looking up a key in the object, the type inference automatically assigns it the type T. However, there is a possibility that it ...

Mysterious data organization - transform into an object

As I interact with an API, there is a value that I cannot quite pinpoint. My goal is to transform this string into a JavaScript object, but the process seems complex and confusing. Does anyone have insight on what this data represents and how it can be co ...

"Code snippets customized for React are not functioning properly in the javascriptreact.json file within Visual Studio Code

I'm looking to incorporate some customized React.js code snippets into my Visual Studio Code setup. I am aware of the two files in VSCode that handle this - javascript.json and javascriptreact.json. Although the snippets work well in javascript.json, ...

Associating functions with events within objects

I am encountering a unique issue with jQuery and JavaScript in general. Currently, I am developing a JS file that allows me to create portlets for a client's website. I am utilizing SignalR to send updates to the users. The code snippet below is cau ...

What is the best way to assess each item in an array and apply the useState() hook based on a specific condition

I am currently working on a simulation for a blackjack hand and have run into an issue with my code. The game follows these steps: users receive two random cards and a total point value, then click 'hit' to draw another random card from the deck. ...

Transmitting an array of objects via Ajax to PHP

Assistance Needed: I have created my object using the following code: var data = []; $("#report-container [id^='report-']").each(function(index) { var reportObject = { "subject" : "", "photo" : "", "rating" : "", ...

Is there a way to create a JavaScript script that automatically updates a webpage for all users simultaneously?

I have developed a web application that enables users to modify content using JavaScript. Currently, these changes are only visible on the local browser and do not involve AJAX. However, I am wondering how I can ensure that these DOM alterations are refle ...

Angular only allows click events to trigger during a push

Is there a way to reveal the password without requiring a click, but simply by pushing on an eye icon? My code HTML <input [formControlName]="'password'" [type]="isShow ? 'text' : 'password'" class=&qu ...

Utilize Jquery to locate and update the text of all div elements that have an empty id attribute

I need help with a task involving a list of divs, some with ids and some without. My goal is to identify all the divs within a specific class that have empty ids and change their inner text to say "no data available". Can this be done? My attempt using $( ...

No results returned by Mongoose/MongoDB GeoJSON query

I have a Schema (Tour) which includes a GeoJSON Point type property called location. location: { type: { type: String, enum: ['Point'], required: true }, coordinates: { type: [Number], required: true ...

Shifting and positioning the card to the center in a React application

I am currently constructing a React page to display prices. To achieve this, I have created a Card element where all the data will be placed and reused. Here is how it appears at the moment: https://i.stack.imgur.com/iOroS.png Please disregard the red b ...

Is it common practice to include a variable in a function with the same name as the function itself?

Is it common practice to use a variable with the same name as the function within the function itself? const sum = function(arr) { let sum = 0; for(let i = 0; i < arr.length; i++) sum += arr[i]; return sum; }; Although this code runs s ...

What is the best way to extract the information from the checkbox in a MUI datatable?

I am struggling to transfer an array with checked values to another table in order to display only those values. How can I achieve this? I am relatively new to using react and I find it challenging to grasp how some of the functions and components work. I ...

Highchart displays results for each individual line without the use of commas

I am interested in creating a chart using Highchart with three lines. The first two lines will display data similar to [4.12, 3.34, 5.45] / [3.45, 5.45, 3.23], while the third line should be displayed without any commas, showing results like [7, 4, 2]. Can ...

Decoding JSON data from the Twitch API

I am currently working on retrieving a user's Twitch name using json_decode and their Steam ID, but I keep encountering an error that I can't seem to resolve. Despite researching similar issues faced by other users, I haven't made any progre ...

JavaScript Page Search - Error in Finding Single Result

I am currently working on implementing a 'find in page' search box and have come across some JavaScript code that is working really well. Everything works great when there are multiple strings, as pressing enter cycles through the results and the ...

Center a sans-serif font vertically with exact precision while adjusting the font size

My issue is an expansion of a previous problem I mentioned in another question, which can be found here Vertically align sans-serif font precisely using jquery/css. To summarize: I am aiming to align two divs containing text, with one positioned above the ...

Ignoring Json in ASP .NET doesnt appear to be functional

Issue Encountering difficulties with serializing an object in MVC .Net when returning a json result due to loop references. Error message: Self referencing loop detected for type ... Defining my entity class: public class Subscriber { [JsonIgnore] ...

The Apollo Client mutation input type is missing data

Currently, I am working with Apollo-client and facing an issue while making a mutation on the client. It seems that when I perform my mutation, the data being passed to the server becomes void. Below is my mutation type: type: recipeType, args:{ ...

How to import JSON file in Python without the 'u prefix in the key

Recently, while working on a Python project involving graphs, I encountered an issue with saving certain data structures in files for quick retrieval. One particular problem arose when I attempted to save a dictionary in JSON format using the json.dump fun ...