I need to pass a JSON object to a separate function in python
import json
userList = [{username: 'userName', email: 'email'}]
listString = json.dumps(userList)
print(json.loads(listString))
this will print the same object: [{username: 'userName', email: 'email'}]
I know it isn't possible to pass a JSON object directly to another function which is why I'm turning it into a string and trying to unpack it in the new function
testFunction(listString)
def testFunction(oldList):
print(json.dumps(oldList))
this will print out [{'username': 'userName', 'email': 'email'}] but won't let me return the object from the new function. What do I need to do to fix this?
def testFunction(oldList):
newList = json.loads(oldList)
# code to append to newList
return newList
Response: null
json.loads()?