Are you beginning to work with NoSQL or Document Databases? If that’s the case, then it will be good to have a brief knowledge of JSON Modeling. Because shifting from Relational Databases to schema-less Databases allows you to build more flexible applications and handle even semi-structured data.

Like in the Relational data model, you need to design the schema and analyze the data requirements before going live. Similarly, JSON Modeling will help you organize data with ease. With the high demand for fast query performance, storing data in JSON format is best suited for this.

In this article, you will learn about JSON Modeling and how it differs from Relational tables. Also, you will go through the JSON data model process, and rules to follow while converting from Relational data to documents. And, at last, we will cover an example JSON data model example in Java.

Table Of Contents

What is JSON?

Data Modeling: JSON Logo | Hevo Data
Image Source

JSON (JavaScript Object Notation) is a lightweight and open standard file format that uses human-readable text for storing and transporting data. It’s a data-interchange format that transmits data objects that contains key-value pairs and arrays to store data. It’s easy for machines to parse and generate. JSON is based on a subset of the JavaScript programming language and was originally designed as an alternative to XML. Also, it’s a language-independent format which means it supports every kind of language, framework, and library.

JSON is a widely-used text notation/format used for structured data. The key application of JSON is exchanging data among web clients and web servers. JSON media type is application/json and file extension is .json. JavaScript offers a global JSON Object that can streamline your JSON conversions and allow you to use this format easily.

Basic JSON Syntax

Data Modeling: JSON Syntax | Hevo Data
Image Source

Rules:

  • <KEY>:<VALUE> Data is in key/value pairs.
  • Data is separated by commas.
  • Objects are enclosed in curly braces ({}).
  • Arrays are enclosed in square brackets ([]).
{"employees":[
  { "firstName":"John", "lastName":"Doe" },
  { "firstName":"Anna", "lastName":"Smith" },
  { "firstName":"Peter", "lastName":"Jones" }
]}

In JSON, values must be one of the following data types:

  • a string
  • a number
  • an object
  • an array
  • a boolean
  • null
Empower Data Modeling with Hevo’s No-code Data Pipeline

Hevo Data, a fully-managed Data Modeling solution, can help you automate your Data Modeling processes in just a few clicks. With Hevo’s blazing-fast Data Pipelines, you can extract & model data from 150+ Data Sources into your Data Warehouse, Database, or any destination of your choice. You can also process raw data using Hevo’s robust & built-in transformation without writing a single line of code!

Get Started with Hevo for Free

Hevo is the fastest, easiest, and most reliable data replication platform that will save your engineering bandwidth and time multifold.

Experience an entirely automated hassle-free Data Modeling. Try our 14-day full access free trial today!

What is Data Modeling?

Images Source

Data Modeling is a process of generating a visual representation of an entire information system to express relations between data and structures. It revolves around analyzing and defining all different data points business collects and generates and also managing relationships between data points. The process itself is an exercise to get a better understanding and clarification of the data requirements as per business needs.

Data Modeling enforces business rules, regulatory compliances, and government policies on the data. It defines how data will flow into and out of the Database. Data Models are the blueprint for designing a new or existing Database or legacy application. Data Modeling is a core Data Management discipline.

JSON Modeling for Document Databases

JSON Modeling bind controls to JavaScript object data which is generally specified in JSON format. It’s a client-side model and does not support mechanisms that involve server-side paging or loading. JSON Modeling doesn’t support any for sending data back to the server. 

JSON Modeling has a data model for document Databases consisting of a structured hierarchy. A document in the JSON data model may contain embedded documents as data. In JSON Modeling each document with data represent the attributes of an entity. Documents are organized into collections that are equivalent to tables in Relational Databases. 

Here is an example of JSON Modeling for better understanding, conversion from Relational table to JSON format is shown in the image below:

Data Modeling: Relational Table to JSON Format | Hevo Data
Image Source

Normalization vs Denormalization

Normalization is the best approach to deal with Relational Databases to maintain data and avoid redundancy. But when it comes to non-Relational Databases or NoSQL, denormalization is the best approach to follow. It is just the opposite of Normalization. Here, all related data for an entity is compressed into a single document in NoSQL Database. 

Normalization involves constructing tables and building relationships between those tables using certain rules. These rules remove redundancy, and inconsistency to make data more flexible. Whereas Denormalization has a redundant schema. This is done to improve the query performance. JSON Modeling is a technique of combining the data into a single table to make data retrieval faster. Here is an example of Relational Database tables in a Normalized manner, and the same data is shown using JSON Modeling in a Denormalized fashion.

Data Modeling: Normalized Form of Data
Image Source
Data Modeling: Denormalized Form of Data | Hevo Data
Image Source
What Makes Hevo’s Data Modeling Experience Unique

The Data Modeling process can be time-consuming and tedious without using the right set of tools. Hevo’s automated No Code platform helps in enriching your Data Modeling with its blazing-fast Data Pipeline. Our platform has the following in store for you!

  • Exceptional Security: A Fault-tolerant Architecture that ensures Zero Data Loss.
  • Built to Scale: Exceptional Horizontal Scalability with Minimal Latency for Modern-data Needs.
  • Built-in Connectors: Support for 100+ Other Sources, including Databases, SaaS Platforms, Files & More. Native Webhooks & REST API Connector available for Custom Sources.
  • Data Transformations: Best-in-class & Native Support for Complex Data Transformation at fingertips. Code & No-code Flexibility ~ designed for everyone.
  • Smooth Schema Mapping: Fully-managed Automated Schema Management for incoming data with the desired destination.
  • Blazing-fast Setup: Straightforward interface for new customers to work on, with minimal setup time.

Want to take Hevo for a spin? Sign Up here for a 14-day free trial and experience the feature-rich Hevo.

JSON Modeling Process

In this section, you will learn how to perform JSON Modeling in NoSQL Databases using an example. It’s a good practice to start with Entity-Relationship modeling to define the entities, relationships, and attributes for the application. 

Entities are the main objects, Attributes are properties of the objects and Relationships are connections between Entities. This can be one-to-one, one-to-many, many-to-many, etc. Let’s take the example of social media applications. The E-R diagram for social media applications is shown below. 

JSON Modeling: E-R diagram for social media application | Hevo Data
Image Source

In the above diagram, the Entities are User, Post, and Comment. Relationships are user makes a post, a post has comments, and a post belongs to a category. The Relational model of this example is shown below.

JSON Modeling: Relational model for social media application | Hevo Data
Image Source

Here, users are stored in the user table. The posted URL is stored in the Post table with a foreign key to the user that posted it, and a foreign key to the category for the post. Comments about a post are stored in the comments table with a foreign key to the post and a foreign key to the user that commented.

Now, you have to just Denormalize this diagram and you will get a JSON data model.

Rules for JSON Modeling

Some rules to follow when performing JSON Modeling or converting Relational tables to JSON models.

  • If the Relationship is one-to-one or one-to-many then store related data as nested objects.
  • If the Relationship is many-to-one or many-to-many then store related data as separate documents.
  • If data reads are mostly parent fields then store children as a separate document. 
  • If data reads are mostly parent + child reads then store children as nested objects.
  • If data writes are mostly either parent or child then store children as separate documents.
  • If data writes are mostly either parent and child both then store children as nested objects.

Example of JSON Modeling Using Java

In this section, you will go through an example of a Java class that will act as a JSON Model in the application. Let’s take an example of Yelp sample data fetched from the API in JSON format.

{
  "businesses": [
    {
      "id": "yelp-tropisueno",
      "name" : "Tropisueno",
      "display_phone": "+1-415-908-3801",
      "image_url": "http://s3-media2.ak.yelpcdn.com/bphoto/7DIHu8a0AHhw-BffrDIxPA/ms.jpg",
      ...
    }
  ]
}

Now as this data contains 4 attributes – id, name, phone, and image URL. Now if you have to generate a data model for this data in Java. Then it would look like as shown below.

public class Business {
	private String id;
	private String name;
	private String phone;
	private String imageUrl;

	public String getName() {
		return this.name;
	}

	public String getPhone() {
		return this.phone;
	}

	public String getImageUrl() {
		return this.imageUrl;
	}
}

Conclusion 

In this article, you learned about Data Modeling and the basic syntax of JSON. Then you read about JSON Modeling, how it is different from Relational Database, and how it delivers better query performance over relational tables. You also went through the process of JSON Modeling and an example of how to code JSON data models in Java.

Visit our Website to Explore Hevo

Companies need to analyze their business data stored in multiple data sources. Data needs to be loaded to the Data Warehouse to get a holistic view of the data. Hevo Data is a No-code Data Pipeline solution that helps to transfer data from 150+ data sources to desired Data Warehouse. It fully automates the process of transforming and transferring data to a destination without writing a single line of code.

Want to take Hevo for a spin? Sign Up here for a 14-day free trial and experience the feature-rich Hevo.

Share your experience of learning about JSON Modeling in the comments section below!

mm
Former Research Analyst, Hevo Data

Aditya has a keen interest in data science and is passionate about data, software architecture, and writing technical content. He has experience writing around 100 articles on data science.

No-code Data Pipeline For your Data Warehouse

Get Started with Hevo