# How to print json data on console

**URL:** <https://community.postman.com/t/how-to-print-json-data-on-console/12861>\
**Category:** Help Hub\
**Created:** [May 25, 2020, 4:54am UTC](https://community.postman.com/t/how-to-print-json-data-on-console/12861 "2020-05-25T04:54:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mason](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@mason](https://community.postman.com/u/mason)\
**Post date:** [May 26, 2020, 3:50am UTC](https://community.postman.com/t/how-to-print-json-data-on-console/12861/2 "2020-05-26T03:50:00Z")

</div>

# Overview

You are looking to console.log(“stuff”)

## A little bit more

If you use console.log, you will always have to modify your script to get rid of it ☹ since it always runs. Might be better to wrap the log in something.

### Simple but powerful change

Use the globals to hold a `debug` variable so that you can change change it from 0 and 1 depending on if you want to debug. You can setup the value in the collection, folder, or request pre-script too.

### Here is what I do

Here is what I usually use in my scripts:

```
const debug = pm.globals.has("debug") && (pm.globals.get("debug") == 1)

function log(msg){
    debug && msg && console.log(`LOG: ${msg}`)
}

```

That should give you what you want if you now do this in test for the request:

```
    const debug = pm.globals.has("debug") && (pm.globals.get("debug") == 1)

    function log(msg){
        debug && msg && console.log(`LOG: ${msg}`)
    }

log(`Here is the json: ${JSON.stringify(pm.response.json())}`)

```

## What’s all that && stuff about?

So, the && stuff is part of javascript and others have written about it in the community.  
[https://community.postman.com/t/sharing-tips-and-tricks-with-others-in-the-postman-community](https://community.postman.com/t/sharing-tips-and-tricks-with-others-in-the-postman-community)  
Look for May 13 '19 and you can find more.

---

_[View the full topic](https://community.postman.com/t/how-to-print-json-data-on-console/12861)._
