JavaScript Object Notation

Lesson Details:
November 30, 2020


I: Introduction

Json is a format used to store data. It uses javascript objects to store data. The object notation is very simple. The json format was first introduced in 2001 by an online company called yahoo. The format was released as an open source format to be used for any purpose. There are many other formats that are similar to json but they are not widely used.

A: Json quick introduction to json data javascript using json

Json can be read and written by any language that supports the standard library. This includes python, javascript, c#, go, ruby, java, etc.

There are many different types of data that can be stored in json. Below are the main types of data that can be stored in json:

Objects - this is the most common type of data that is stored in json. Object keys must be limited to 32 characters.

- this is the most common type of data that is stored in json. Object keys must be limited to 32 characters. Strings - this type of data may contain any text.

- this type of data may contain any text. Numbers - this type of data can be either integers or floating point values. There is no restriction on the size of the number.

- this type of data can be either integers or floating point values. There is no restriction on the size of the number. Booleans - this type of data can only be true or false.

- this type of data can only be true or false. Arrays - this type of data can hold an unlimited amount of items. The items must all be of the same type.

- this type of data can hold an unlimited amount of items. The items must all be of the same type. Null - this type of data cannot have a value associated with it at all times. It contains a placeholder that indicates that it has no value.

npm install text-json --save

const json = require('text-json'); const file = process.argv[2]; let jsonText = await json(file); console.log(jsonText);

In the above example we convert a file from an object notation to a string using text-json . You can use a content based approach as well if your file had a header with a first column named “type” and a first row named “name” then you could do something like below:

const json = require('text-json'); const file = process.argv[2]; let jsonText = await json(file); console.log(jsonText); const columns = {}; const rows = {}; try { await json({ headers: [{ name: 'column', type: 'string' }, { name: 'row', type: 'string' }], name: 'object', columns: columns, rows: rows }); } catch (error) { console.log(error); }

I: Conclusion

loader
Course content