A better way to visualize API response normalized with "Normalizr"

186 Views Asked by At

I have this normalized API response :

{
  "result": "123",
  "entities": {
    "articles": {
      "123": {
        "id": "123",
        "author": "1",
        "title": "My awesome blog post",
        "comments": [
          "324"
        ]
      }
    },
    "users": {
      "1": {
        "id": "1",
        "name": "Paul"
      },
      "2": {
        "id": "2",
        "name": "Nicole"
      }
    },
    "comments": {
      "324": {
        "id": "324",
        "commenter": "2"
      }
    }
  }
}

Are there any better ways to visualize/log/debug (an already normalized or while normalizing) a response other than console.log() used with JSON.stringify() ?

1

There are 1 best solutions below

0
Antonio Cozzi On

There are actually many NPM modules like pretty-print-json or json-beautify that can do this for you as well al libraries, although my favorite method for pretty-printing is still the console.log() paired with JSON.stringify() because you can easily use the remaining arguments for beautify in console.

JSON.stringify() provides you a replacer and a space args:

  1. The replacer allows you to keep in the stringified object the attributes that you want, so he finds in place the attribute and keeps it in the string;
  2. The space defines the tabulation, is used to insert white space into the output JSON string for readability purposes only.