Graziano Dimatteo
Graziano Dimatteo

Reputation: 197

Nodejs how to use map of object?

Hi i have a json like this called body:

{
  data: {
    id:1,
    name:hallo
  },
  paging: {
    cursors: {
      next: "abc"
    }
  }
}

so I have to save it into a map and then I'll need to print or to modify it. If I save it with this code

var Map = require("collections/map");

var new_body = JSON.parse(body)
var map = new Map(new_body);

I have some difficulties to print for example map.paging.cursor.next, how can I do it? maybe I had to define a structure of that map before inserting the json inside it, I don't know...

Upvotes: 0

Views: 6616

Answers (1)

shan1024
shan1024

Reputation: 1399

Your json have errors. Correct them like this.

{
  "data": {
    "id": 1,
    "name": "hallo"
  },
  "paging": {
    "cursors": {
      "next": "abc"
    }
  }
}

Then you can parse the json like this and get the paging.cursors.next value.

var map = JSON.parse(body);//This will parse the json string

Now map.paging.cursors.next will have the value "abc"

Upvotes: 1

Related Questions