How to convert the given data into JSON?

时间:2018-03-25 20:03:41

标签: javascript json node.js

I want convert the following data into JSON object. But when is used JSON.parse() command it returns:

var r = JSON.parse(t)
    SyntaxError: Unexpected token o in JSON at position 1

Here is sample data string which is to be converted

 var t = { message: 
       [ { timestamp: 1522007930599,
           tags: [Array],
           _id: '5aacb7cc0281b558debacf26',
           message_link: 'String',
           __v: 0 },
       ] }

1 个答案:

答案 0 :(得分:1)

JSON.parse converts from JSON to a JavaScript data structure.

To go the other way you need JSON.stringify