Welcome back!

Forgot your password?

Parsing JSON in Node.js

A lot of APIs will give you responses in JSON format. Here we'll review JSON parsing in Node.js so that you can get to the interesting data faster.

This tutorial assumes that you've already gone through our Node.js getting started tutorial and are familiar with how our Node.js SDK works. Although we use the output from our YouTube ListSearchResults Choreo in this tutorial, the same steps we outline here will work for parsing any JSON in Node.js.

Get JSON output

2 Enter any search term you want for the Query input and click Generate Code to test the Choreo from our website.

3 You get a whole bunch of JSON in the Response output. These are the results of the search. Next we'll see how to parse through this response in Node.js and pick out only the pieces we're interested in.

Parse it in Node.js

4 Create a new .js file and copy in the code below. In steps 5-8, we'll go over what happens in the code.

6 Next, we parsed out the piece of data we want from the JSON. It helps to look at the JSON file's structure to get an idea of how it is organized. The two main elements you should look for are:

Class name

How it appears in the JSON file

JSONArray

"name": [

JSONObject

"name": {

For these results, we wanted the title and description of the first video in the search results. To do this, you'll use the following square bracket syntax for specifying the items array, then the first item in that array (at index 0), and finally the snippet object within the first item in the array:

Location

Description

data["items"]

The array of videos in the search results

data["items"][0]

The first video within those results

data["items"][0]["snippet"]

The snippet containing descriptive details of each video

7 To finish up, the title and description properties nested within the snippet object are assigned to variables.

8All finished! Run the code to try it out. You should see the title of your first YouTube Search result in the console.

What next?

You should to able to parse all sorts of JSON responses with our Node.js SDK now. You can find lots of JSON to play with in our Library of over 2000+ Choreos.

Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.

Commit Code to GitHub

Commit Temboo-generated code directly to GitHub and share with the world. Learn more.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.