UI-data contracts: enhancing client-side JSON data validation

I have encountered situations where the JSON data I receive from services and database calls, created by a different team, contains invalid data combinations that lead to unintended errors downstream.

For example, in the case below, if the "rowContent" field is set to "1", its corresponding "row" should be a populated JavaScript object. While "rowContent1" and "row1", as well as "rowContent2" and "row2" are correct pairings, "rowContent3" and "row3" do not match up properly.

I understand that the structure of this JSON is not ideal. It may seem a bit unconventional but this closely resembles what I am dealing with in production. Unfortunately, I have limited control over it.

Are there any data-driven methods to outline JSON data relationships like this in a way that can validate them before attempting to utilize non-existing data in "row3"?

Alternatively, what steps would you suggest I take in this scenario?

Thank you,

-Larry

{ "table" : [
        { 
            "aRowContent" : {
                "rowContent1" : "1",
                "rowContent2" : "0",
                "rowContent3" : "1",
            },
            "row1" : {
                "myRowValue" : "red"
            },
            "row2" : null,
            "row3" : null
        }
    ]
}

Answer №1

Validation using JSON Schema is limited to the structure of JSON data itself, without referencing other data elements.

The redundancy in your data structure seems to be the root cause here. For instance, why include /table/0/aRowContent/rowContent1 when the same information can be inferred from a null-check on /table/0/row1?

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

Scrolling with Jquery window.scrollTo results in the page becoming unresponsive

I'm currently revamping a website that features a header with 100% screen height, but I need it to shrink down to 0px when a user starts scrolling. The issue I'm facing is that once the header shrinks to 0px, the page content ends up slightly abo ...

Combine the content from several URLs listed in an array using either the .get or .ajax method

Is it feasible to add the content of each URL in the array to a given container from a list of URLs using jQuery? For example: <li class="contacts"><a href="index.php#contact1">Contact 1</a> <li class="contacts"><a href="index. ...

The data field is failing to load the dictionary for the request correctly

I am experiencing difficulties pushing this JSON data request because I suspect that the format might not be passing through correctly as I keep receiving a bad request error. The interesting part is that when I copy the request into my REST client, everyt ...

Encountering issues with accessing image files located in the public folder of my Next.js project - Receiving a 404 Error message

I am currently facing an issue with my Next.js project where I am unable to use image files from the public folder. Despite checking that the file paths, names, and extensions are correct, as well as ensuring my configurations are accurate, I keep encounte ...

Stop capturing mouse and keyboard events within a specific div element on all web browsers

I manage a website with forms that have jquery autosave features and are updated using ajax. These forms include various types of input elements such as textboxes, jQuery UI datepickers, and time pickers... <div id="content"> <form id="line1"&g ...

Quarkus API routes for downloading and uploading JSON documents

I need to develop endpoints for downloading and uploading group configurations in the form of a JSON file. The configuration is currently stored in the database as a JSON object, so when a user wants to download the configuration, it needs to be converted ...

Incorporating a setup file into my JavaScript project

In my JavaScript project, I have both frontend and backend codes (NodeJS). Here is the folder structure for my production environment: /prod /server sourceCode1.js sourceCode2.js ... sourceCodeN.js index.js ...

Difficulty achieving a visually appealing JSON output when using GSON in Scala

Below is the code snippet that I am working with: var json_val = (Json(DefaultFormats).write(map)) The JSON value generated from the above code looks like this: {"Tatyana Nader":[{"source":"Marseille Rail Station (XRF)","amount":"5000.0","points":"500" ...

Processing the retrieved object from Dropbox API using Node.js and Express

I've been attempting to carry out a simple task like uploading a file to Dropbox. The file uploads successfully, but I'm in need of the response that contains details such as the file name, size, and path. I understand that I'm getting lost ...

Vue CLI configured with Webpack is experiencing malfunctions following a recent update to dependencies

I'm sharing my package.json details below: { "name": "x", "version": "1.0.0", "main": "index.js", "license": "MIT", "scripts": { "dev": "webpa ...

Troubleshooting a React JS and material-ui issue

Having an issue with material-ui integration in reactjs. Attempting to render a FlatButton, but encountering the error message: TypeError: _context$muiTheme is undefined As a newcomer to reactjs, I'm unsure of where the problem lies. Below is my code ...

The nearby diversion inexplicably triggers a phantom GET request

My goal is to build a website with specific functionality: If a user tries to access the /home page without authentication, they should be redirected to the /login page. After successfully logging in on the /login page, the user should receive a session c ...

The ts-node encountered an issue with the file extension in this message: "TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension

When using ts-node, I encountered the following error: $ ts-node index.ts TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/projects/node-hddds8/index.ts I attempted to remove "type": "module& ...

Enhancing wordpress custom fields using ajax without overwriting them

Seeking assistance with updating a custom field in WordPress. I have a gallery of images with textareas for comments attached to each image. Currently, I can enter text into a textarea and save it instantly using AJAX to the database. However, when I add a ...

How to eliminate a timestamp from a file using PHP

I'm seeking a solution to remove a timestamp [04-Nov-2014 12:22:17 UTC] from an error_log file using PHP. The timestamps are located at the beginning and end of the file without any line breaks. The structure of the error_log is in JSON format, simila ...

Serializing list objects with Jackson in Spring Boot

In my Spring Boot ReST controller, I am returning a List of "Personnel" objects. The output is mostly fine, but there is an issue that I need to address. Each Personnel object contains a nested object called PersonnelType. When serializing the first Perso ...

Guide on decrypting a file encrypted with C# using Node JS

I currently have encrypted files in C# using DES and PKCS7 encryption. My objective is to decrypt these files in Node JS. The decryption code in C# that I am using appears like this: public string SSFile_Reader( string fileToDecrypt ) { DESCryptoService ...

Setting up a Celery task from Java: "Unknown message received and deleted. Incorrect destination specified"

I need help with scheduling a Celery task from Java. Here's how I'm sending the task to RabbitMQ: ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); connection = factory.newConnection(); channel = connection.crea ...

Leveraging variables in a GET call

For a while now, I've been struggling with a seemingly simple issue. When I try to make a GET request using parameters in the query, it just doesn't work for me. However, if I use a full query without parameters, it works fine. Here is the code ...

Synk: the presence of a self-signed certificate within the certificate chain

Recently, I've been encountering the error message Synk Protect is showing "self-signed certificate in certificate chain" when I try to run npm install on a project of mine. Would appreciate any help or tips on how to identify which out of the 984 pac ...