Take the 2-minute tour ×

I want to create the following JSON object, as seen from a console log:

    .   member: Object
    .   id: 8286

I've been trying:

'member' :[{'id': 8286}]

but get the following error: "Uncaught SyntaxError: Unexpected token :"

What am I doing wrong? Thanks

share|improve this question
I don't upvote to compensate downvotes, but I should. This is a perfectly valid question. –  Júlio Santos Jan 6 '12 at 21:29
@JúlioSantos, that's a good rule, though. You might think the question deserves to be at zero, but you are giving the requestor +8 rep. In this case, that's probably fine, but in general it often rewards bad or mediocre questions. –  Justin Satyr Jan 6 '12 at 21:32
Try to you something like jshint.com –  jake Jan 6 '12 at 21:32
Do you want to create JSON or a JavaScript object? Have you read a JavaScript Guide at all? –  Felix Kling Jan 6 '12 at 21:38
show 4 more comments

3 Answers

up vote 5 down vote accepted
var member = {
    id: 8286

this allows you to access it like


You could have also meant something like:

var data = {
    member: {
        id: 8286

which you would access like so:


If this is not what you want, please clarify in your post cause I'm not sure I'm following your request correctly.

share|improve this answer
add comment

You're missing the curly braces surrounding the object. As in:

var x = {'member': [{'id':8286}]};
share|improve this answer
It's not JSON, but OP is probably meaning a JavaScript object. –  Felix Kling Jan 6 '12 at 21:37
@FelixKling who's OP? –  Oliver Nov 28 '13 at 21:46
add comment

You mean something like this?

    "member": {},
    "id": 8286
share|improve this answer
thats kind of what i thought but i think id needs to be in member to make sense... so obj->member->id –  Kai Qing Jan 6 '12 at 21:35
Then you mean var obj = {"member":{"id":8286}}, which can then be accessed with obj.member.id –  fivedigit Jan 6 '12 at 21:37
add comment

Your Answer


