How to pass nested list to REST end-point in Python?

I have the following list in Python:

[['type1', 'type2'], [], [], [], [], [], []]

and I need to pass it as a parameter to my REST end-point. If I pass it as it is, then the error is thrown because it’s a list. If I convert it into a string using str(mynestedlist), then I don’t know how to convert it back to the list in the end-point.

Any help is appreciated.

Answer

If you use requests you can do:

lst = [['type1', 'type2'], [], [], [], [], [], []]

response = requests.post(API_URL, json=lst).json() # response is now standard python dictionary/list

On the server you get all POST data in form of Json. So you can use json.loads() on them. Return a Json data.