How to pretty print JSON.stringify output

JSON.stringify is a method of JSON global which converts valid JSON to a serialized string

JSON is an abbreviation of 'JavaScript Object Notation' it's an independent data type that is not specific to JavaScript programming language.

JSON is a global object with methods for manipulating JSON data

JSON.stringify is a method that converts JSON to a string its may be used for debug or simply to serialize JSON

It accepts three arguments (JSON, FUNCTION, SPACER)

JSON: maybe an array or object

FUNCTION: Is an influencer it's a middle man that alters what is to be returned

SPACER; Is a character used to indent or prettyfiy output

For instance take a look;

const name = 'John'
const surname = 'swana'
const me = {name, surname}

JSON.stringify(me, null, '    ')

Returns the following output;

    'name': 'John',
    'surname': 'swana'


Popular posts from this blog

Open-graph meta data tags introdution

What is 'this.' keyword in JavaScript

How to create zip archives in nodejs

what is 'array.includes' function in JavaScript

How to build a twitter retweet bot using JavaScript