Skip to content

Pass json.dumps parameters in DeepDiff.to_json #226

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

Closed
joaonc opened this issue Jan 21, 2021 · 1 comment
Closed

Pass json.dumps parameters in DeepDiff.to_json #226

joaonc opened this issue Jan 21, 2021 · 1 comment

Comments

@joaonc
Copy link

joaonc commented Jan 21, 2021

Is your feature request related to a problem? Please describe.
DeepDiff.json(...) uses json.dumps(...) and json.dumps has a few parameters (namely indent) that I'd like to use.

Describe the solution you'd like
to_json(...) could either have arguments used by dumps (ex: skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, sort_keys=False) or simply have **kwargs that get passed to dumps.

so either:

def to_json(
    default_mapping=None, skipkeys=False, ensure_ascii=True, check_circular=True,
    allow_nan=True, cls=None, indent=None, separators=None, sort_keys=False):
    ...
    return json.dumps(
        dic,
        default=json_convertor_default(default_mapping=default_mapping),
        skipkeys=skipkeys,
        ensure_ascii=ensure_ascii,
        ...)

or

def to_json(
    default_mapping=None, **kwargs):
    ...
    return json.dumps(
        dic,
        default=json_convertor_default(default_mapping=default_mapping),
        **kwargs
)

Describe alternatives you've considered
The alternative I did was to pretty much duplicate DeepDiff.to_json(...)'s functionality in order to use indent:

json_str = json.dumps(ddiff.to_dict(), default=json_convertor_default(), indent=2)

Additional context
This allows for more powerful usage of DeepDiff.to_json(...).

@seperman
Copy link
Owner

Hi @joaonc
This feature is covered in DeepDiff 5.2.3: https://zepworks.com/deepdiff/current/serialization.html#to-json
https://twitter.com/sep_dehpour/status/1361774255050870789

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

No branches or pull requests

2 participants