267

I cannot find an answer to this one:

My AJAX calls return JSON data. In Google Chrome Developer Tools > Resources > XHR when I click on the resource on the left and then on the Content tab I see the JSON string as a string and not as a tree as Firebug and Firebug Lite do.

How do I force Chrome to display it as a tree. Is there a Content-type that my PHP file must have???

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
GRboss
  • 6,239
  • 5
  • 21
  • 20

11 Answers11

528

To see a tree view in recent versions of Chrome:

Navigate to Developer Tools > Network > the given response > Preview

Matt McClure
  • 16,009
  • 2
  • 28
  • 30
74

Google Chrome now supports this (Developer Tools > Network > [XHR item in list] Preview).

In addition, you can use a third party tool to format the json content. Here's one that presents a tree view, and here's another that merely formats the text (and does validation).

Trevor
  • 13,085
  • 13
  • 76
  • 99
10

You can use Google Chrome Extension: JSONView All formatted json result will be displayed directly on the browser.

Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
Quang Vu
  • 362
  • 3
  • 4
6

The correct content-type for JSON data is application/json. I assume that is what you are missing.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 7
    Unfortunately this still doesn't force Chrome to turn the JSON string into tree. Thanks though! – GRboss Oct 08 '10 at 08:42
3

I've found the answer:

You MUST encode your json like this: {"c":21001,"m":"p"} but not {c:21001,m:"p"} or {'c':21001,'m':'p'}

Thus, the key of a dict must be wrapped in double quotes:", then chrome will preview it as json rather than plain text.

Chadwick
  • 12,555
  • 7
  • 49
  • 66
  • 7
    That's because the first one is valid JSON and the other examples are not (although they are valid javascript). See http://simonwillison.net/2006/oct/11/json/ – styfle Dec 04 '12 at 01:34
2

In order for it to display the JSON message properly it has to have the "application/json" mime type and to be correctly structured.

You can check the structure here

Mariana B.
  • 437
  • 5
  • 14
1

I'm not sure if Chrome has added this feature since the last answer, but I was able to view the json response by...

  • opening developer tools in the browser while on the page with the request
  • submitting the request
  • in developer tools - "Console" tab - click on the "Object" tree under the resource to expand

...I was able to view the response as a readable hierarchy that showed what to ask for and what is returned. (Neither Network or Resources tab had anything helpful that I was able to find.)

Happy requesting!

Deborah
  • 4,316
  • 8
  • 31
  • 45
1

There was an issue with a build of Google Chrome Dev build 24.0.1312.5 that caused the preview panel to no longer display a json object tree but rather flat text. It should be fixed in the next dev

See more here: http://code.google.com/p/chromium/issues/detail?id=160733

JeffBaumgardt
  • 1,378
  • 3
  • 16
  • 24
1

How to get Tree-view

See step by step instructions on how to do this in the below GIF. (I recorded in Chrome - chromium shouldn't be too different.)

Click on the link to enlarge and follow along

How to get the tree view of the response in chrome

BenKoshy
  • 33,477
  • 14
  • 111
  • 80
0

I don't think the Chrome Developer tools pretty print XHR content. See: Viewing HTML response from Ajax call through Chrome Developer tools?

Community
  • 1
  • 1
lambacck
  • 9,768
  • 3
  • 34
  • 46
0

Chrome now has a button for pretty printing responses. Its the {} in the bottom left of the "Response" window:

The toggle button

Benjamin Buch
  • 4,752
  • 7
  • 28
  • 51
Ilummini
  • 29
  • 6