I want a conditional loop which should read json file, and print "postId" based on "user_name" matches an item in the list.
I tried these baby steps to see, but it did not work
Python version: 2.7.5 OS: Linux
here's python script:
import sys
import re
import json
my_list = ['windows-super-user','linux user','unix_super_user']
for list_item in my_list:
with open('strings.json') as f:
d = json.load(f)
for userid in d:
if list_item == user_name:
print("Here's the user name :" +user_name+ ", and post id :" +postid)
Here's the strings.json file content;
[
{
"postId":"328e9497740b456154c636349",
"postTimestamp": "1521543600",
"pageType": "/home.php:topnews",
"viewTime": 1521545993647,
"user_name": "windows-super-user",
"gender": 3,
"likes": "8",
"id": "ffa1e07529ac917f6d573a",
"postImg": 1,
"postDesc": [753],
"origLink": 0,
"duration": 0,
"timestamp": 9936471521545,
"back_time": 1521545993693
},
{
"postId":"15545154c636349",
"postTimestamp": "547773600",
"pageType": "/home.php:topnews",
"viewTime": 45993647,
"user_name": "linux user",
"gender": 3,
"likes": "8",
"id": "695e45a17f6d573a",
"postImg": 1,
"postDesc": [953],
"origLink": 0,
"duration": 0,
"timestamp": 545993647,
"back_time": 85993693
},
{
"postId":"9098897740b456154c636349",
"postTimestamp": "899943600",
"pageType": "/home.php:topnews",
"viewTime": 1521545993647,
"user_name": "unix_super_user",
"gender": 3,
"likes": "8",
"id": "917f6d573a695e45affa1e07",
"postImg": 1,
"postDesc": [253],
"origLink": 0,
"duration": 0,
"timestamp": 193647,
"back_time": 1521545993693
},
]
Expected output:
Here's the user name : windows-super-user , and post id : 328e9497740b456154c636349
Here's the user name : linux user , and post id : 15545154c636349
Here's the user name : unix_super_user , and post id : 9098897740b456154c636349