Is it possible to search through a JSON and find a single string? I just want to know if this sting is in the JSON or not.
What I have tried before:
def parse_string(self, reg_string, input_data):
self.logger.info("parse string")
for i in input_data:
self.logger.info(input_data[i])
if input_data[i] == reg_string:
return (input_data[i])
else:
self.logger.info('regex: %s not found', reg_string)
but it prints lots of Nones.
My JSON:
{
"id": 5931,
"state": "opened",
"created_at": "2020-09-24T15:04:05.728+02:00",
"author": {
"id": 130,
"username": "veeti",
"state": "active"
}
How I call the method:
parser.parse_string("veeti", parser.data)
Advertisement
Answer
You could do str(json_value).find("veeti") > -1