Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import json in Python code generator? #426

Closed
michalrus opened this issue Nov 26, 2020 · 0 comments · Fixed by #430
Closed

import json in Python code generator? #426

michalrus opened this issue Nov 26, 2020 · 0 comments · Fixed by #430
Assignees
Labels
enhancement New feature or request

Comments

@michalrus
Copy link

michalrus commented Nov 26, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants