Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse json from the current page in browser developer tools console

When looking at the results of a url in my browser and I would like to open up the Developer Tools javascript console and use javascript commands to analyze the results of the page. Here's an example page:

http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=ju6z9mjyajq2djue3gbvv26t&q=deep&page_limit=2&page=1

Note - I'm changing the url for this - rotten tomatoes' URL isn't public and my key expired. This example from jsontest works with the accepted answer.

http://echo.jsontest.com/movies/ET

Is there a way to click on this, launch the firebug console (or something similar in another browser) and parse this json string so I could use common javascript to inspect the json object.

EDIT

JQuery is not available...

like image 758
Mark Swardstrom Avatar asked Oct 07 '13 20:10

Mark Swardstrom


People also ask

How do I display JSON data in my browser?

Right click on JSON file, select open, navigate to program you want open with(notepad). Consecutive opens automatically use notepad.

What are the methods to parse JSON?

The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.


1 Answers

In Chrome, I opened the link above and went to Chrome's Developer Tools (F12) and entered the following command in the console...

JSON.parse(document.body.textContent)

It returns a the object representation quite nicely. From there is an easy matter to manipulate and play with the object in Javascript. For instance...

JSON.parse(document.body.textContent).movies.length

...returns 2.

like image 100
Aron Boyette Avatar answered Oct 11 '22 15:10

Aron Boyette