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'
}

Comments

Popular posts from this blog

What is 'this.' keyword in JavaScript

How to iterate array elements using 'for loop' in JavaScript