O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using JSONPath in your web application

Using JSONPathwith JavaScript in your web application is easy. You only need to include the jsonpath.js implementation in your application, and then use its jsonPath function.

Getting ready

Before you begin, you need to download the JavaScript jsonpath library from https://code.google.com/p/jsonpath/ and include it in the scripts your HTML page uses with a script tag, like this:

<html>
<head>
<title>…</title>
<script type="text/javascript" src="jsonpath.js"></script>
</head>

The jsonPath function takes a JSON object (not as a string, but as a JavaScript object) and applies the path operation to the contents, returning either the matched values or a normalized path. Let's see an example.

How to do it…

Here's an ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required