JSON File Format

JSON file format stands for JavaScript Object Notation. It is a collection of ordered(array) and unordered(object) set of data. It is a lightweight data interchange format. JSON file can be easily read and written by human beings and also can be parsed and generate easily by machines. It is a text format which is language independent. JSON file format consists of the complex object and array structure.

Where JSON files can be used?

JSON can be used for web service response. Previously web services used XML as primary format for transmitting the data but now JSON is preferred over XML because it is more lightweight as compared to XML

How a JSON File looks like

JSON file is built on two structures:-

1) Object: It is a collection of name/value pair. This is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.

2) Array: An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

Object in JSON File

Object is an unordered set of name/value pair data. Consider below example to understand this.

{“name” : “ABC” , “id” : “123” , “age” : “24”, “country” : “India”}

Data inside curly braces ({}) represent an example of the object in JSON file.

Object starts with the left curly brace ({) and ends with the right curly brace(}).

Data between curly braces are available in key/value pair. Value to each name is followed by :(colon) and name/value pair is separated by ,(comma). Here in the example “id” : “123” , –> id belongs to name family and 123 belongs to the column family which is separated by :

1.gpeg

                                                          Pic Courtsey: json.org

Array in JSON File

Array is ordered collection of the values. An array satrt with left brace([) and ends with right brace(]), values are separated by ,(comma). Consider teh below example to understand this

“state” : [“Running”], “process_Completed” : [“90”]

In the above example state and Running represent one set of array

2

                                             Pic Courtsey: json.org

Value

value can be string in double quotes or a number or true or false or null or an object or an array in nested format structure.

3

                                                    Pic Courtsey: json.org

Apart from the object and array notation, json can be stored as string and numeric notations.

 

How a JSON Schema looks like?

Consider below sample JSON to understand the schema

{“name” : “ABC” , “id” : “123” “age” : “24”, “country” : “India”,

“property” : {“key” : “1”, value : “2”, host : “abc”},

“state” : [“Running”], “process_Completed” : [“90”]}

JSON schema looks like:-

root

|– name : String

|– id : String

|– age : String

|– country : String

|– property : struct

| |–key : String

| |–value: String

| |–host : String

|–state : array

| |–element : String

|--prrocess_Completed : array

| |–element : String

Here property is of type value which contains three key/pair values and state and process_Completed represents array type.This is how a simple file looks like.Schema can be more complex depending on the structure of JSON file.

How we can leverage this JSON file in Hadoop and what is the way to parse this JSOn file, will continue in next post.

Leave a comment