Schema for JSON object with dynamically generated keys

I have a specific request that follows a certain format:

{
   "uuid_1": [{obj}, {obj}, {obj}],
   "uuid_2": [{obj}, {obj}],
   ...
   "uuid_n": [{obj}, {obj}],
}

The object 'obj' is a simple object that contains a few IDs, such as:

{
 id: string,
 userId: string,
}

I want to maintain this JSON format as making changes would involve additional data processing on both the frontend and backend.

It is important to note that the uuids are generated randomly, so I cannot predict what uuids to expect.

So far, I have specified that the keys of the object must be in uuid format using:

"propertyNames": { "format": "uuid" }

My question is, how can I define a JSON schema for the values within this object? Thank you.

Answer №1

Big shoutout to @mplungjan for pointing out the magic of Pattern properties, I managed to create the schema below. (Sharing in case it helps someone).

{
    "type": 'object',
    "propertyNames": {
        "format": "uuid"
    },
    "patternProperties": {
        ".*": {
            "type": "array",
             "items": {
                "type": "object",
                "required": ['id', 'userId'],
                "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "userId": {
                        "type": "string",
                        "format": "uuid"
                    }
                }
             }
        }
    }
}

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

What is the best way to have my sliding panel automatically close when I click outside of it?

I have created a sleek sliding navigation panel for my website that appears when the screen width is reduced. Although I am satisfied with how it functions currently, I would like the panel to close when the user clicks/taps outside of it. What adjustments ...

Using custom class instances or objects within Angular controllers is a simple process

Using three.js, I have created a class called threeDimView that houses my scene, camera, and other elements. In my JavaScript code, I instantiate a global object of this class named threeDimView_. threeDimView_ = new threeDimView(); Now, I wish to displa ...

What is the best way to adjust the size of a canvas and then upload the resized information to a

I need to update the user's database table row data with new resized dimensions (changing width and height). For instance: In my online editor, I create a canvas of size 1000x500, add objects, and save -> This data is sent to the database When re ...

The process of matching the full names of the source and destination Strings in Node.js

Need assistance comparing two strings with a third string in a JSON Array for full names var source = intentObj.slots.toPlazaName.value.toString(); // Jaipur var destination = intentObj.slots.fromPlazaName.value.toString(); // Kishangarh Compare with t ...

Maximizing the power of Webpack alongside Google Maps API

I have been using Webpack along with the html-webpack-plugin to compile all my static files. However, I am facing an issue when integrating it with the Google Maps API. Here is the code snippet: var map; function initMap() { map = new google.maps.Map(d ...

Utilizing AngularJS to filter prices within a specific range using a button

I am new to using angularjs and I am working on implementing a price range filter with nouislider for a list of products with different prices. I want the filtering to happen only after the user clicks on the filter button. Below is the HTML code for my " ...

Set the error state of a TextField in Material UI to true based on the user's input

Being a newcomer to React and Javascript, I have made some progress but now find myself stuck. I am struggling with how to change the error state of a Material UI TextField based on user input. Specifically, I want the error to be triggered if the user inp ...

Create a typing effect in Javascript that mimics the user's input

Trying to simulate a typing effect with the sentence extracted from user input using JavaScript, but encountering some issues. Successfully capturing and displaying the input in the console with console.log(), however, incorporating the typing effect func ...

The Art of Determining the Text's Baseline

My goal is to create a test that determines whether the text rendered inside an <input> has the same baseline as a label: To achieve this, I want to calculate the baseline of the rendered text in each element and compare their values. Is it possible ...

Creating a line chart using data from a MySQL database with the help of PHP and

After completing a program, I am now tasked with extracting data from MySQL and presenting it using HTML/PHP. The data retrieval process involves utilizing the mysql.php file: <?php $hostname = "localhost"; $database = "database"; $username ...

Develop an enhancement for the Date object in Angular 2 using Typescript

Using the built-in Date type, I can easily call date.getDate(), date.getMonth()...etc. However, I am looking for a way to create a custom function like date.myCustomFunctionToGetMonthInString(date) that would return the month in a string format such as &a ...

When making a jQuery + AJAX request, IE8 is causing a null return value

I'm completely stumped as to why this issue is happening. To start, the code has been checked and validated by the W3C validator as HTML5, except for some URL encoding problems (such as & needing to be &amp;), but I don't have the ability ...

Invoke data-id when the ajax call is successful

Initially, there was a smoothly working "like button" with the following appearance: <a href="javascript:void();" class="like" id="<?php echo $row['id']; ?>">Like <span><?php echo likes($row['id']); ?></span ...

JavaScript embedded in an HTML document, which in turn is embedded within JavaScript

Is it possible to nest tags within other tags to control the functionality of a download button in a chat bot? Unfortunately, nesting tags is not allowed, so I'm looking for an alternative solution. Below is the complete HTML file I'm working wit ...

Customize the toggle icon for the accordion in Framework7

I took inspiration from the custom accordion elements provided in the documentation and made some alterations to the icons. However, I'm facing an issue with getting the toggle functionality of the icons to work properly. My goal is to have a "+" dis ...

Why is the value of the select element in AngularJS an object?

Here is a JSON object: { "9000A": { "LOCname":"A Place", "LOCid":"9000A" }, "2700C": { "LOCname":"C Place", "LOCid":"2700C" }, "7600B": { "LOCname":"B Place", "LOCid":"7600B" } } To ...

What could be causing the issue with this function not loading correctly the first time in Node.JS?

I am currently in the process of developing a Twitter bot using Node.JS. One issue I am facing is with a function that utilizes an npm library called "scrapejs" to extract data from Yahoo Finance. The problem arises when this function loads after the initi ...

Utilizing the Linux grep command to extract key values from a JSON file

My dilemma lies in handling the JSON output I have, which contains a list of objects stored within a variable (I hope I expressed that correctly). I've tried executing a curl command to obtain the output, but unfortunately, I'm unable to share i ...

The Material-ui bug: multiple instances of the modal opening when a button is clicked

I have the following code in my render() method: render() { const classes = this.useStyles(); return ( <Paper style={classes.root}> <Table style={classes.table}> <TableBody> {this.state.deadTopics ...

Ways to implement the function provided in the website using javascript

Exploring the world of JavaScript functionality as a beginner, I am eager to try pasting dynamic data into HTML. I came across a helpful link providing instructions on how to achieve this using a table format. However, despite my best efforts, I am strugg ...