[HOW TO] Trying to display JSON in a readable format…..

I am getting back a JSON string from an API that looks kind of like this locations, addresses, passwords all blurred out)…..

​

[incoming json])

I need it to be formatted something like this….

​

[desired format])

…but I can’t find a way to do that.

I need it in a more readable form so I can see what is coming in from the current API and compare it to a second API that should send in the same info. If there is a difference I need to be able to change the second API to make it’s output equal the first API.

​

3 Comments
  1. I’m not quite sure I follow this.

    Where do you need this formatting?

    The browser you can use:

    You can also copy and paste the output into a formatter like this:

    You could also use a tool like Postman to see formatted JSON from the endpoint:

  2. There’s a PHP function called json_encode() and you can pass the JSON_PRETTY_PRINT flag to make it pretty:

    “`
    echo json_encode( $json, JSON_PRETTY_PRINT );
    “`

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer