0

I have the following JSON response and I'm trying to get given_title.

{ status: 1,
  complete: 1,
  list: 
   { '890245271': 
      { item_id: '890245271',
        resolved_id: '890245271',
        given_url: 'http://davidwalsh.name/open-graph-data-nodejs',
        given_title: 'Get Open Graph Data with Node.js',
        favorite: '0',
        status: '0',
        time_added: '1443782532',
        time_updated: '1443784021',
        time_read: '0',
        time_favorited: '0',
        sort_id: 0,
        resolved_title: 'Get Open Graph Data with Node.js',
        resolved_url: 'http://davidwalsh.name/open-graph-data-nodejs',
        excerpt: 'Two of this blog\'s most popular posts are Facebook Open Graph META Tags and How to Create a Twitter Card.  I\'m not at all surprised because we as content creators want some visual control over how our site is represented and shared on third party sites, especially social media sites.',
        is_article: '1',
        is_index: '0',
        has_video: '0',
        has_image: '0',
        word_count: '214' } },
  error: null,
  search_meta: { search_type: 'normal' },
  since: 1444393955 }

This is what I tried in the view

<% data.list.890245271.forEach(function(item) { %>
   <p><%= item.given_title %></p>
<% }); %>

But I'm getting an error on the web page Unexpected number in /Users/xxxxx/Dev/Project/views/index.ejs while compiling ejs

I'm obviously doing something wrong here with 890245271but not sure how to do it right to get what I need.

Seong Lee
  • 10,314
  • 25
  • 68
  • 106
  • 1
    "I have the following JSON response" — That isn't JSON. See http://jsonlint.com/ – Quentin Oct 09 '15 at 13:13
  • I validated it on that site and I had a parse error there. But I'm not sure why this isn't JSON? This is the format I expected to get as per the API provider's documentation which they claim JSON https://getpocket.com/developer/docs/v3/retrieve – Seong Lee Oct 09 '15 at 13:21
  • In JSON, property names must be strings (not identifiers) and strings can't be delimited with single quotes. The example response in the documentation you link to is valid JSON. The data in your question is not. – Quentin Oct 09 '15 at 13:23

0 Answers0