-1

i have to acess some variables and transform them back to json format.

They are stored in columns, i have:

name = request.values['name']
age = request.values['age']

This gives me back something like:

John 23

How to transform this to:

'{"name":"John", "age":"23"}'

1 Answers1

2

You can use json.dumps (read "dump string"):

json.dumps(request.values)

If you only want a subset of the dictionary you can use:

json.dumps({k: request.values[k] for k in ('name', 'age')})
a_guest
  • 34,165
  • 12
  • 64
  • 118