Skip to content

import json in Python code generator? #426

@michalrus

Description

@michalrus

Is your feature request related to a problem? Please describe.
I’m a bit surprised that the Python generator doesn’t import json (which is a part of stdlib), and generate JSON payloads as regular dictionaries, instead of hard to read (and edit) already encoded strings.

Describe the solution you'd like
Just import json on top, and then you can do something like:

#!/usr/bin/env python

import json

current_payload = '{"a": 1, "b": "some \\n string"}'

better_dict_payload = {
    'a': 1,
    'b': 'some \n string'
}

future_payload = json.dumps(better_dict_payload)

print('current =', current_payload)
print('future  =', future_payload)
print('equal?   ', current_payload == future_payload)

resulting in:

current = {"a": 1, "b": "some \n string"}
future  = {"a": 1, "b": "some \n string"}
equal?    True

Now, better_dict_payload is much-much more readable, and easy to edit.

Additional context
n/a

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions