How to Beautify JSON - Demo
Now before we jump into the demo and write some JSON first let’s take a look at the information that we would like to use in our JSON example. Here the sample.txt file is going to represent a patient and his/her disease history. This document intends to visualize how we use the information to form the JSON object.
The first thing we want to have is the patient demographic information like the patient ID, Name, Gender, and so on in the EMR application. Then we want to have a series of details about the patient's disease history, which will be a list of different diseases the patient had in the past. So for each disease, we need to know what is the name of the disease and at which date the patient consulted the physician, and what is the name of that physician. Here this physician information can be multiple.
Now we are going to create the JSON document for this information in this file and as you can see here that the extension of this file is Test.JSON. As we have learned that every JSON object starts with curly braces just like a C# or a Java method and within these braces, we will add different fields as key-value pairs.
Each field is separated by a comma then a colon and here our first field is going to be the patient ID. After then, put the value of the ID. We have a patient name and the value of that key. In the same way, we have Gender, and as you can see here that the name of the key is in double quotes and then there is a colon and value of that key.
Now we have Strings, Numbers and the final type of value that we are going to see to be used in the JSON document field is an Array. As we know that as per this document we have a list of disease history. So it's common that any person could be having multiple diseases. Here we are going to use the Array Syntax beginning and ending with square braces. First of all, give the key name and define the square braces within this Array let us define the disease history object.
So to begin with, let's just write out the consult date and then define the disease name. Then write the physician's name to whom this patient consulted. Now as you can see that our JSON document is created as per the given information in this sample.txt file.
It's time to validate this JSON whether we have created a valid JSON or not. For that ByteScout has provided one utility in which you can validate the JSON as well as you can also beautify it. Open that utility in the browser and let's validate this JSON.
I have already copied the JSON which we have just created and pasted it over here. Click on the Format button and clicking on this button it will validate this JSON as well as also format this JSON.
Other useful articles:
- Essential Secrets of JSON - Introduction to JSON
- JSON Components and Specifications
- Real-World Example of JSON Usage with PDF.co Cloud API
- Why Should I Use JSON Format
- JSON vs XML
- How to Structure JSON – Demo Overview
- How to Beautify JSON
- How to Explore JSON
- Explore JSON Demo using AJAX
- Real-World Example of JSON Usage with PDF.co Cloud API
- Common Mistakes and Gotcha Part 2
- JSON vs CSV vs XML
- Getting Started with JSON Schema
- JavaScript vs JSON
- JSON vs BSON vs GSON
- JSON vs YAML vs TOML