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

How to set content disposition header for nginx server to force content download

Animated daylight on HTML5 Canvas

How to make a static http server in nodejs using express

JS13K Preparation

Adding Gameover and introduction screen on HTML Canvas