Languages
[Edit]
EN

JavaScript - simple own json schema

9 points
Created by:
Frida-Timms
667

In this short article we would like to show how in JavaScript write simple logic to manage simple JSON schema.

The article contains three parts:

  1. example schmeas,
  2. simple logic that let us to fill empty properies in some object to unify object with schema,
  3. simple logic that let us to validate object according to schema.

Example schemas

Edit

Below array contains simple usage cases only, but it is verry easy to understand the template. The main idea of the schema is to use type property to describe JSON part type: boolean, number, string, array or object.

Simple object:

Edit
Example schemnaExample JSON

Simple array:

Edit
Example schemnaExample JSON

Nested object:

Edit
Example schemnaExample JSON

Nested array:

Edit
Example schemnaExample JSON

Filling missing properties example

Edit

In this section we would like to show how to write simple logic that let us to fill a object with null properties if some fields defined in JSON Schema were not defined in the object that we want to unify. 

Simple JSON Schema validator example

Edit

This section contains example JSON Schema validation logic.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join