Home Interests JavaScript

How to Pretty Print JSON in Chrome Developer Console

howchoo
howchoo   (467)
September 14, 2023
2 minutes

Share

Interests
Posted in these interests:
code • 11 guides
javascript • 4 guides
webdev • 10 guides

This short guide will show you how to pretty print a JSON object in the Chrome Developer Tools console.

1 – Output your object as a string

Wrap your object in JSON.stringify and log it to the console:

const currentlyDrinking = {
    beer: 'Yeungling',
    container: 'bottle',
    empty: true
};

console.log(JSON.stringify(currentlyDrinking));

This will result in the following minified object:

{"beer":"Yeungling","container":"bottle","empty":true}

Not exactly pretty yet, so we’ll need to format it. This is especially important for larger objects.

2 – Format the pretty-printed output

To format our object, we’ll need to specify the number of spaces we’d like:

const currentlyDrinking = {
    beer: 'Yeungling',
    container: 'bottle',
    empty: true
};

console.log(JSON.stringify(currentlyDrinking, undefined, 4)); // use 4-space tabs to format and indent the code

This results in:

{
    "beer": "Yeungling",
    "container": "bottle",
    "empty": true
}

Much better!

3 – More formatting options

For more Chrome Developer console object pretty-printing options, check out the JSON.stringify() MDN docs.

NEXT UP

Secure Your Sensitive Data with Kubernetes Secrets

Learn how to create and use Kubernetes secrets.
howchoo   (467)
November 26, 2023

Kubernetes secrets are objects that store and manage sensitive data inside your Kubernetes cluster. One mistake developers often make is storing sensitive information like database passwords, API credentials, etc in a settings file in their codebase. This is very bad practice (hopefully for obvious reasons). Most developers know this, but still choose the option because it’s easy.

Continue Reading

howchoo

 467 guides

Introducing Howchoo, an enigmatic author whose unique pen name reflects their boundless curiosity and limitless creativity. Mysterious and multifaceted, Howchoo has emerged as a captivating storyteller, leaving readers mesmerized by the uncharted realms they craft with their words. With an insatiable appetite for knowledge and a love for exploration, Howchoo's writing transcends conventional genres, blurring the lines between fantasy, science fiction, and the surreal. Their narratives are a kaleidoscope of ideas, weaving together intricate plots, unforgettable characters, and thought-provoking themes that challenge the boundaries of imagination.

Discover interesting things!

Explore Howchoo's most popular interests.

Explore