0

I've json object ( this json object returned from database):

{ created_at: 'Wed Nov 21 19:28:24 +0000 2012', id: 271334264140869630, id_str: '271334264140869633', }{ created_at: 'Wed Nov 21 19:28:24 +0000 2012', id: 271334264140869630, id_str: '271334264140869633', }

When I've use JSON.stringify(obj) ->

{ "created_at": "Wed Nov 21 19:28:24 +0000 2012", "id": "271334264140869630", "id_str": "271334264140869633" }{ "created_at": "Wed Nov 21 19:28:24 +0000 2012", "id": "271334264140869630", "id_str": "271334264140869633" }

This obj invalid on http://jsonlint.com/, because error:Expecting 'EOF', '}', ',', ']'

Pls help me fix this error.

2
  • 5
    The javascript object returned from the database is not valid either in what you posted. Commented Dec 6, 2012 at 8:06
  • Are you stringifying and printing in a loop? Please show some of the code that generates all this. Commented Dec 6, 2012 at 8:06

1 Answer 1

1

Below is your valid JSON.

[
    {
        "created_at": "WedNov2119: 28: 24+00002012",
        "id": 271334264140869630,
        "id_str": "271334264140869633"
    },
    {
        "created_at": "WedNov2119: 28: 24+00002012",
        "id": 271334264140869630,
        "id_str": "271334264140869633"
    }
]
  1. If multiple objects are present in parent Object, it forms an array and should be separated by comma ",". The array should be wrapped with squre brackets "[]"
  2. The Id of an object must be string, for being validated by jsonlint. If value is string, quote it with double quotes "".

This is the jsfiddle to test stringify operation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.