Monday, 12 June 2017

06.06.2017.

Tuesday.




JSON


JSON: JavaScript Object Notation.

JSON is a syntax for storing and exchanging data.

JSON is text, written with JavaScript object notation.



When exchanging data between a browser and a server, the data can only be text.

JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server.

We can also convert any JSON received from the server into JavaScript objects.

This way we can work with the data as JavaScript objects, with no complicated parsing and translations.



Storing Data

When storing data, the data has to be a certain format, and regardless of where you choose to store it, text is always one of the legal formats.




Why use JSON?

Since the JSON format is text only, it can easily be sent to and from a server, and used as a data format by any programming language.

JavaScript has a built in function to convert a string, written in JSON format, into native JavaScript objects:

JSON.parse()



JSON Syntax Rules

JSON syntax is derived from JavaScript object notation syntax:
  • Data is in name/value pairs
  •  
  • Data is separated by commas
  •  
  • Curly braces hold objects
  •  
  • Square brackets hold arrays




JSON Values

In JSON, values must be one of the following data types:
  • a string
  •  
  • a number
  •  
  • an object (JSON object)
  •  
  • an array
  •  
  • a boolean
  •  
  • null
In JavaScript values can be all of the above, plus any other valid JavaScript expression, including:
  • a function
  •  
  • a date
  •  
  • undefined





JSON Uses JavaScript Syntax

Because JSON syntax is derived from JavaScript object notation, very little extra software is needed to work with JSON within JavaScript.





JavaScript Arrays as JSON

The same way JavaScript objects can be used as JSON, JavaScript arrays can also be used as JSON.
 


Valid Data Types

In JSON, values must be one of the following data types:
  • a string
  •  
  • a number
  •  
  • an object (JSON object)
  •  
  • an array
  •  
  • a boolean
  •  
  • null

Object Syntax

JSON objects are surrounded by curly braces {}.

JSON objects are written in key/value pairs.

Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null).

Keys and values are separated by a colon.

Each key/value pair is separated by a comma.




No comments:

Post a Comment

Machine Learning Annotation Introduction

Data annotation in Machine Learning is the process of annotating/ labeling data to categorize the dataset to identify by ML models. It can b...