Pass JSON as Input
Assuming the client passed input as JSON, you can easily convert the input data to a python dictionary:
# json/app.py
import json
def cape_handler(data):
try:
x = json.loads(data)
return x
except json.decoder.JSONDecodeError:
return 'please pass valid json'
You can pass this json via the CLI.
Valid JSON:
$ cape test json '{"hello": "world"}'
{'hello': 'world'}
Invalid JSON:
$ cape test json hello world
please pass valid json