How to get only one Json value using request.get_data() Flask Python

Asked

Viewed 229 times

1

I’m a Python beginner and a hint to get only one value from the following Json.

{
  "test1":"valortest1",
  "test2":"valortest2",
  "test3":"valortest3",
  "test1":"valortest1"
}

Use to get json as follows in flask. data = request.get_data()

I get the complete file as a return by printing the given variable, but I would like to handle this better by printing only the value2.

What would be the best way to accomplish this process?

  • can use request.form['test1']

1 answer

0

You can access the value through the key directly: The get_json method already converts JSON to a dictionary.

json = request.get_json()
valor2 = json['test2']
print(valor2)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.