How can i read this json with python?

Ramazan

Regular Member
Joined
Aug 19, 2018
Messages
441
Reaction score
310
JSON:
[
  "python",
  [
    [
      "python for beginners",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python full course",
      0,
      [
        512
      ]
    ],
    [
      "python tutorial",
      0,
      [
        512
      ]
    ],
    [
      "python projects",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python dersleri",
      0,
      [
        512,
        433,
        131
      ]
    ],
    [
      "python api",
      0,
      [
        512,
        433,
        131
      ]
    ],
    [
      "python course",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python course for beginners",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python threading",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python programming",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python tutorial for beginners",
      0,
      [
        512
      ]
    ],
    [
      "python in 100 seconds",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python matplotlib",
      0,
      [
        433,
        131
      ]
    ]
  ],
  {
    "k": 1,
    "q": "H2-rUOKlO-QybvwPAGefws5iZVY"
  }
]
I just need the text on elements no need 0 value or anothers it should be like:

["python for beginners", "python", "python full course"]

thanks for help.
 
Python:
import json

text = "{'whatever':'value'}"
data = json.loads(text)

print(data['whatever'])

However, what you have there is not json. Not the standard format anyway. What you have there is a list of lists.
You can parse it directly as a list with indices.

E.g. python[0][1][2]
 
Python:
import json

text = "{'whatever':'value'}"
data = json.loads(text)

print(data['whatever'])

However, what you have there is not json. Not the standard format anyway. What you have there is a list of lists.
You can part it directly as a list with indices.
Idk I really stuck at this. If i want to loop that elements how should i do because api response is my shared data thanks.
 
Idk I really stuck at this. If i want to loop that elements how should i do because api response is my shared data thanks.
Python:
text = [
  "python",
  [
    [
      "python for beginners",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python full course",
      0,
      [
        512
      ]
    ],
    [
      "python tutorial",
      0,
      [
        512
      ]
    ],
    [
      "python projects",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python dersleri",
      0,
      [
        512,
        433,
        131
      ]
    ],
    [
      "python api",
      0,
      [
        512,
        433,
        131
      ]
    ],
    [
      "python course",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python course for beginners",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python threading",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python programming",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python tutorial for beginners",
      0,
      [
        512
      ]
    ],
    [
      "python in 100 seconds",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python matplotlib",
      0,
      [
        433,
        131
      ]
    ]
  ],
  {
    "k": 1,
    "q": "H2-rUOKlO-QybvwPAGefws5iZVY"
  }
]
    
keyword_list = [data[0] for data in text[1]]
print(keyword_list)

This is going to print:
1663936055903.png


If you're working with python, you might as well try to educate yourself with the basics at least.
These are common things you can learn in a day.
 
Python:
text = [
  "python",
  [
    [
      "python for beginners",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python full course",
      0,
      [
        512
      ]
    ],
    [
      "python tutorial",
      0,
      [
        512
      ]
    ],
    [
      "python projects",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python dersleri",
      0,
      [
        512,
        433,
        131
      ]
    ],
    [
      "python api",
      0,
      [
        512,
        433,
        131
      ]
    ],
    [
      "python course",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python course for beginners",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python threading",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python programming",
      0,
      [
        512,
        433
      ]
    ],
    [
      "python tutorial for beginners",
      0,
      [
        512
      ]
    ],
    [
      "python in 100 seconds",
      0,
      [
        433,
        131
      ]
    ],
    [
      "python matplotlib",
      0,
      [
        433,
        131
      ]
    ]
  ],
  {
    "k": 1,
    "q": "H2-rUOKlO-QybvwPAGefws5iZVY"
  }
]
  
keyword_list = [data[0] for data in text[1]]
print(keyword_list)

This is going to print:
View attachment 226420

If you're working with python, you might as well try to educate yourself with the basics at least.
These are common things you can learn in a day.
Yeah i'm trying to do my best thanks for help. I'm familar with mysql and json pretty confuse me :)
 
However, what you have there is not json. Not the standard format anyway. What you have there is a list of lists.
You can parse it directly as a list with indices.

E.g. python[0][1][2]

That is completely valid JSON but you're correct in saying that he can access elements through indexes.


Idk I really stuck at this. If i want to loop that elements how should i do because api response is my shared data thanks.
@Alexion has provided you with a working solution which you can take as is. But... The problem is that you won't learn anything that way. Programming requires you to attempt solving problems yourself and solving hard problems on your own is how you become better, that's how you achieve that "Aha! I get it now!" moment.

Solution to your problem requires understanding of loops and arrays which is very basic knowledge that you will be using on a daily basis if you intend to write code. Alexion's example is very concise which is good because you can still attempt to solve this problem on your own producing more code but it'll be more obvious and I propose you do exactly that.
 
That is completely valid JSON but you're correct in saying that he can access elements through indexes.



@Alexion has provided you with a working solution which you can take as is. But... The problem is that you won't learn anything that way. Programming requires you to attempt solving problems yourself and solving hard problems on your own is how you become better, that's how you achieve that "Aha! I get it now!" moment.

Solution to your problem requires understanding of loops and arrays which is very basic knowledge that you will be using on a daily basis if you intend to write code. Alexion's example is very concise which is good because you can still attempt to solve this problem on your own producing more code but it'll be more obvious and I propose you do exactly that.
Don't u think I'm not searched this on google? Already have solutions for different type json:
Code:
for result in json.loads(response.text)[1]:
        results.append(result)
    data = json.dumps(results, indent=1, ensure_ascii=False)
But this one is was different for me and spent 1 hour on this.
I'm working on health industry as a SEO and my side hustle is software now writing my saas for this and using php html css mysql python and jquery trying to learn everything if you don't have any idea about me you shouldn't be biased.

Also have many backlink, seo audit bots which is written by me. I'm pretty know how to learn something. Thanks for advice.
 
I'm working on health industry as a SEO and my side hustle is software now writing my saas for this and using php html css mysql python and jquery trying to learn everything if you don't have any idea about me you shouldn't be biased.

Also have many backlink, seo audit bots which is written by me. I'm pretty know how to learn something. Thanks for advice.
I don't get why you're mad. You were clearly stuck on loops and array manipulation. There's no fault in that. Wrapping your head around these things requires time and practice and that was my advice.
 
I don't get why you're mad. You were clearly stuck on loops and array manipulation. There's no fault in that. Wrapping your head around these things requires time and practice and that was my advice.
I'm not mad this section made for asking questions but you trying to explain different things I'm not even asked how to learn something maybe you can bring your solution and explain your code how it works then i can learn something but this way is pretty strange.
 
Back
Top