Learn about the Creation of Various JSON Objects

0
2842
JSON Objects

JSON Objects

In the last chapter, we discussed about the various data types permitted in JSON format along with its overview and example. In this chapter, we are going to discuss about the JSON Objects in detail. We can create JSON object with JavaScript. The following are the ways to create JSON objects with the help of JavaScript.

Creation of JSON Objects
The following are the different types of JSON Objects which are frequently used in the JSON format documents.

1. Empty JSON Object: An empty object, which can be created with the syntax as “var JSON_Object = {};”
2. New JSON Object: A new Object which can be created with the syntax as “var JSON_Object = new Object ();”
3. Simple JSON Object: A simple object with attributes as subject name and marks of data type as string and number respectively. The attribute values are accessed by using ‘.’ Operator as shown below.

Output
When we execute above HTML code on browser, then we will observe the following output.

subject name and marks

4. Array JSON Objects
• As explained in the last chapter, a JSON array object has the following properties.
• An array is an ordered collection of values.
• An array is represented as an enclosure in square brackets i.e. begins with. [. and ends with.]…
• The values in an array are separated by, (comma).
• Indexing in an array can be started at 0 or 1.
• Arrays are recommended to be used when the key names are sequential integers.
In the following example, we are going to shows the creation of two array objects with the help of JavaScript using JSON format.

Output
When we execute above HTML code on browser, then we will observe the following output.

creation of two array objects

Source code for the creation of various JSON Objects
Conclusion: –
In this chapter, we discussed about the creation of various JSON Objects along with their implementation in the suitable examples.

LEAVE A REPLY

Please enter your comment!
Please enter your name here