0

I would like to create a python script that makes a series of web requests to endpoints that will spit out JSON. After receiving the response, I want to validate that it is well-formed JSON, and not some error page. Also, I will need to insert an API key into the request header to get a proper response. what is the best way to go about doing this in python? Thanks!

2
  • 1
    What's the specific question here? What have you tried already? What level of validation do you need? Would a value error thrown by json.loads be enough? Commented Oct 15, 2013 at 22:46
  • The main questions are: 1. how do i make a request 2. how do I insert the api key into that request. 3. how do i know that the JSON is well-formed. Specifically, I only care that it conforms to the JSON standard, and can be deserialized into some arbitrary object. I am NOT trying to validate against a particluar schema, (nor do i want to). Commented Oct 16, 2013 at 14:28

2 Answers 2

1

To validate the JSON you can use http://python-jsonschema.readthedocs.org/en/latest/

To insert the API key in the header you can use Requests http://docs.python-requests.org/en/latest/user/quickstart/

Sign up to request clarification or add additional context in comments.

Comments

1

Validate the json use json.dump(), if your json object incorect it's return the error, handle the error using try catch and answer to your second question , i think you talking about X-AUTH-TOKEN , if your request return json object use this header.

headers = {
"Content-Type": "application/json",
"X-AUTH-TOKEN": your API Token
}

otherwise use

"Content-type":"application/x-www-form-urlencoded"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.