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 ...

Get JavaScript JSON Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.