I have this json object- it’s abbreviated, but it looks somewhat like the following
{
"q": [
{
"a": [],
"asked_at": "2011-12-08T05:58:45.695958",
"closed_at": null,
"event": "/api/v1/event/2/",
"id": "2",
"is_open": true,
"is_public": true,
"question": "Testing the question entry point with curl",
"updated_at": "2011-12-08T05:58:47.026834",
"user": {
"email": "test@t.com",
"first_name": "",
"last_name": "",
"profile": [],
"username": "wout"
}
},
{
"a": [],
"asked_at": "2011-12-08T05:59:39.941603",
"closed_at": null,
"event": "/api/v1/event/2/",
"id": "3",
"is_open": true,
"is_public": true,
"question": "Testing another question entry point with curl",
"updated_at": "2011-12-08T05:59:43.388709",
"user": {
"email": "test@t.com",
"first_name": "",
"last_name": "",
"profile": [],
"username": "wout"
}
}
]
}
Where q is a question being asked, and every a would be an answer (not shown, no answers are given in this example).
How would I go about it, if I wanted to get only the one item with an id of ‘3’ so that I would be left with a result of:
{
"a": [],
"asked_at": "2011-12-08T05:59:39.941603",
"closed_at": null,
"event": "/api/v1/event/2/",
"id": "3",
"is_open": true,
"is_public": true,
"question": "Here's a test entry point with curl",
"updated_at": "2011-12-08T05:59:43.388709",
"user": {
"email": "test@t.com",
"first_name": "",
"last_name": "",
"profile": [],
"username": "wout"
}
}
Hope someone can help- Thanks alot!
Marco
The grep function can filter an array
This will return an array, so if you’re sure there will only be one result, you can do: