JSON interview questions and answers

1. What is JSON? For what is used for?

JSON (JavaScript Object Notation) is a data storage and communication format based on key-value pair of JavaScript object literals. It is a lightweight text-based open standard designed for human-readable data interchange which is derived from the JavaScript programming language for representing simple data structures and associative arrays, called objects.

In JSON

all property names are surrounded by double quotes.

values are restricted to simple data: no function calls, variables, comments, or computations.

JSON is used for communication between javascript and serverside technologies.

2. How to convert Javascript objects into JSON?

JSON.stringify(value); is used to convert Javascript objects into JSON.

String: string of Unicode characters, must be rapped into double quotes “”

Boolean: True or false

Array: ordered list of 0 or more values

Objects : An unordered collection key/ value pairs

Null: An Empty value

14.What is BSON?

BSON is the superset of JSON, which used by MongoDB.BSON supports the embedding of documents and arrays within other documents and arrays. BSON also contains extensions that allow representation of data types that are not part of the JSON spec.

15.How to convert an Object into JSON? What is the full syntax of JSON.stringify?

JSON.stringify method is used to convert an Javascript Object into JSON.
Syntax: