Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pick Value from Json
#1
Hi

I have a below JSON output. I want to pick the value of "Id" from the JSON result.

[
{
"Attributes": {
"accessories": [],
"age": 32.0,
"blur": {
"blurLevel": "low",
"value": 0.11
}
"occlusion": {
"eyeOccluded": false,
"foreheadOccluded": false,
"mouthOccluded": false
},

"Id": "c8c21d40",
"faceRectangle": {
"height": 154,
"left": 477,
"top": 144,
"width": 154
}
}
]
Reply
#2
is this a valid json ?
Reply
#3
Not at all.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
I fixed your json, since what you posted isn't valid. So the path to the id might not be the same as whatever the real data is. This should be enough to get you going in the right direction, though.

Also, after this post, I'm going to move the thread somewhere more applicable, since this has nothing to do with Python News lol

>>> import json
>>> text = '''
... {
... "Attributes": {
... "accessories": [],
... "age": 32.0,
... "blur": {
... "blurLevel": "low",
... "value": 0.11
... },
... "occlusion": {
... "eyeOccluded": false,
... "foreheadOccluded": false,
... "mouthOccluded": false
... },
...
... "Id": "c8c21d40",
... "faceRectangle": {
... "height": 154,
... "left": 477,
... "top": 144,
... "width": 154
... }
... }
... }
... '''
>>> parsed = json.loads(text)
>>> parsed
{'Attributes': {'accessories': [], 'age': 32.0, 'blur': {'blurLevel': 'low', 'value': 0.11}, 'occlusion': {'eyeOccluded': False, 'foreheadOccluded': False, 'mouthOccluded': False}, 'Id': 'c8c21d40', 'faceRectangle': {'height': 154, 'left': 477, 'top': 144, 'width': 154}}}
>>> parsed['Attributes']['Id']
'c8c21d40'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I pick the right python in Linux env? MDRI 9 3,720 Jun-27-2020, 05:40 PM
Last Post: snippsat
  Python MySQL - How to pick column row data as variable? bharaths 1 4,264 Nov-02-2018, 12:08 PM
Last Post: bharaths
  BaseHTTPServer.HTTPServer pick-a-port? degenaro 1 2,514 Jul-05-2018, 08:36 PM
Last Post: gontajones
  Pick 3 Lotto Code? Python3 4 4,578 Sep-10-2017, 05:09 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020