How to iterate over JSON array? [closed]
I have this JSON array with multiple roots:
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]
I want to iterate over it and print issuer_name
values in Python. Any solution, please?
python json loops
closed as too broad by martineau, petezurich, gnat, Unheilig, lagom Nov 12 at 1:55
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have this JSON array with multiple roots:
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]
I want to iterate over it and print issuer_name
values in Python. Any solution, please?
python json loops
closed as too broad by martineau, petezurich, gnat, Unheilig, lagom Nov 12 at 1:55
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
I think the title of this question is misleading and it is likely a dup of How to find a particular json value by key?.
– martineau
Nov 11 at 20:44
add a comment |
I have this JSON array with multiple roots:
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]
I want to iterate over it and print issuer_name
values in Python. Any solution, please?
python json loops
I have this JSON array with multiple roots:
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]
I want to iterate over it and print issuer_name
values in Python. Any solution, please?
python json loops
python json loops
edited Nov 11 at 20:24
martineau
65.7k989177
65.7k989177
asked Nov 11 at 20:08
W0rm
13
13
closed as too broad by martineau, petezurich, gnat, Unheilig, lagom Nov 12 at 1:55
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by martineau, petezurich, gnat, Unheilig, lagom Nov 12 at 1:55
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
I think the title of this question is misleading and it is likely a dup of How to find a particular json value by key?.
– martineau
Nov 11 at 20:44
add a comment |
I think the title of this question is misleading and it is likely a dup of How to find a particular json value by key?.
– martineau
Nov 11 at 20:44
I think the title of this question is misleading and it is likely a dup of How to find a particular json value by key?.
– martineau
Nov 11 at 20:44
I think the title of this question is misleading and it is likely a dup of How to find a particular json value by key?.
– martineau
Nov 11 at 20:44
add a comment |
1 Answer
1
active
oldest
votes
Use the json
package and load the json. Assuming it is a string in memory (as opposed to a .json
file):
jsonstring = """
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]"""
import json
j = json.loads(jsonstring)
[item["issuer_name"] for item in j]
Gives:
["C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
'C=US, O=Amazon, OU=Server CA 1B, CN=Amazon']
Now, these don't look like names to me, but that's what is assigned to the issuer_name
field, so I think that's something you have to take up with the owner of the data.
If it's a file, you do the loading in this basic pattern:
# something like this
with open("jsonfile.json", "rb") as fp:
j = json.load(fp)
See the docs here: https://docs.python.org/3.7/library/json.html
This is exactly what I am looking for. Thank you very much for you assistance!
– W0rm
Nov 11 at 20:31
That's great @W0rm. If the response helped resolve your issue, mark it as the answer!
– Charles Landau
Nov 11 at 20:56
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the json
package and load the json. Assuming it is a string in memory (as opposed to a .json
file):
jsonstring = """
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]"""
import json
j = json.loads(jsonstring)
[item["issuer_name"] for item in j]
Gives:
["C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
'C=US, O=Amazon, OU=Server CA 1B, CN=Amazon']
Now, these don't look like names to me, but that's what is assigned to the issuer_name
field, so I think that's something you have to take up with the owner of the data.
If it's a file, you do the loading in this basic pattern:
# something like this
with open("jsonfile.json", "rb") as fp:
j = json.load(fp)
See the docs here: https://docs.python.org/3.7/library/json.html
This is exactly what I am looking for. Thank you very much for you assistance!
– W0rm
Nov 11 at 20:31
That's great @W0rm. If the response helped resolve your issue, mark it as the answer!
– Charles Landau
Nov 11 at 20:56
add a comment |
Use the json
package and load the json. Assuming it is a string in memory (as opposed to a .json
file):
jsonstring = """
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]"""
import json
j = json.loads(jsonstring)
[item["issuer_name"] for item in j]
Gives:
["C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
'C=US, O=Amazon, OU=Server CA 1B, CN=Amazon']
Now, these don't look like names to me, but that's what is assigned to the issuer_name
field, so I think that's something you have to take up with the owner of the data.
If it's a file, you do the loading in this basic pattern:
# something like this
with open("jsonfile.json", "rb") as fp:
j = json.load(fp)
See the docs here: https://docs.python.org/3.7/library/json.html
This is exactly what I am looking for. Thank you very much for you assistance!
– W0rm
Nov 11 at 20:31
That's great @W0rm. If the response helped resolve your issue, mark it as the answer!
– Charles Landau
Nov 11 at 20:56
add a comment |
Use the json
package and load the json. Assuming it is a string in memory (as opposed to a .json
file):
jsonstring = """
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]"""
import json
j = json.loads(jsonstring)
[item["issuer_name"] for item in j]
Gives:
["C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
'C=US, O=Amazon, OU=Server CA 1B, CN=Amazon']
Now, these don't look like names to me, but that's what is assigned to the issuer_name
field, so I think that's something you have to take up with the owner of the data.
If it's a file, you do the loading in this basic pattern:
# something like this
with open("jsonfile.json", "rb") as fp:
j = json.load(fp)
See the docs here: https://docs.python.org/3.7/library/json.html
Use the json
package and load the json. Assuming it is a string in memory (as opposed to a .json
file):
jsonstring = """
[
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
"name_value": "sub.test.com",
"min_cert_id": 325717795,
"min_entry_timestamp": "2018-02-08T16:47:39.089",
"not_before": "2018-02-08T15:47:39"
},
{
"issuer_ca_id":9324,
"issuer_name":"C=US, O=Amazon, OU=Server CA 1B, CN=Amazon",
"name_value":"marketplace.test.com",
"min_cert_id":921763659,
"min_entry_timestamp":"2018-11-05T19:36:18.593",
"not_before":"2018-10-31T00:00:00",
"not_after":"2019-11-30T12:00:00"
}
]"""
import json
j = json.loads(jsonstring)
[item["issuer_name"] for item in j]
Gives:
["C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3",
'C=US, O=Amazon, OU=Server CA 1B, CN=Amazon']
Now, these don't look like names to me, but that's what is assigned to the issuer_name
field, so I think that's something you have to take up with the owner of the data.
If it's a file, you do the loading in this basic pattern:
# something like this
with open("jsonfile.json", "rb") as fp:
j = json.load(fp)
See the docs here: https://docs.python.org/3.7/library/json.html
answered Nov 11 at 20:25
Charles Landau
1,8771215
1,8771215
This is exactly what I am looking for. Thank you very much for you assistance!
– W0rm
Nov 11 at 20:31
That's great @W0rm. If the response helped resolve your issue, mark it as the answer!
– Charles Landau
Nov 11 at 20:56
add a comment |
This is exactly what I am looking for. Thank you very much for you assistance!
– W0rm
Nov 11 at 20:31
That's great @W0rm. If the response helped resolve your issue, mark it as the answer!
– Charles Landau
Nov 11 at 20:56
This is exactly what I am looking for. Thank you very much for you assistance!
– W0rm
Nov 11 at 20:31
This is exactly what I am looking for. Thank you very much for you assistance!
– W0rm
Nov 11 at 20:31
That's great @W0rm. If the response helped resolve your issue, mark it as the answer!
– Charles Landau
Nov 11 at 20:56
That's great @W0rm. If the response helped resolve your issue, mark it as the answer!
– Charles Landau
Nov 11 at 20:56
add a comment |
I think the title of this question is misleading and it is likely a dup of How to find a particular json value by key?.
– martineau
Nov 11 at 20:44