I am using python and REST API to post JSON data. My code reads a JSON file containing data from a Remedy change request and collects values for variables in a 500-line JSON object that I post to another program.
Also, it may be necessary to add multiple lines of JSON to be posted depending on the action in the change ticket.
I realize that 500 lines isn't very large, but it looks clunky in my python code and I wondered if there is a different or preferred way for posting JSON that needs to be "manipulated" before posting? Maybe do all of the manipulation to the JSON file in one python script, then do the POST of the ("ready") JSON file in a different python script?
Thanks,
Steve
So . . . I am not asking how to write the code. I am asking whether best practice is to have the JSON object that I POST as lines within the python code that does the request / POST or . . . some other way.Python comes with a built-in package called json for encoding and decoding JSON data.
State one of these...
1) I'm generating a JSON payload in a POST command to another Website.
2) I'm providing a service which receives a POST, form which I'll pull a JSON payload to decode for some type of work.
Tip: Either option will likely be much shorter than 500 lines of code.
Answering the above questions, then attaching your Python code will likely produce best comments.