I am currently trying to parse some data from a post request response and I keep getting this error: \"TypeError: list indices must be integers or slices, not str\"
In my case:
[
{
"_index": "abc",
"_type": "abc",
"_score": null,
"_source": {
"layers": {
"frame_raw": [
"frame": {
......
"raw": [
Correct way to access "raw" values is
data = json.load(json_file)
data[0]['_source']['layers']['raw'][0]
data[0]['_source']['layers']['raw'][1]
...
In case of multiple data:
[
{
"_index": "abc",
"_type": "abc",
"_score": null,
"_source": {
"layers": {
"frame_raw": [
"frame": {
......
"raw": [
{
"_index": "abc",
"_type": "abc",
"_score": null,
"_source": {
"layers": {
"frame_raw": [
"frame": {
......
"raw": [
Get it by:
data = json.load(json_file)
for d in data:
print(d['_source']['layers']['raw'][0])
data['result']['results'] is an array so you can't do ['name'] you need an int, you could add [0] after['results'] and it should work. Then you can reference keys within the object in results.