Skip to content

Ability to pass formatting arguments to JSON backends #77

@timbernat

Description

@timbernat

Feature description

It would be nice if one could natively specify how JSONCollection instances format fields to on JSON dump, e.g. assigning indent, ensure_ascii, separators, etc arguments as found in the json.dump signature

Proposed solution

As a loose implementation, one might unpack the **kwargs passed to JSONCollection.init and isolate those which match the call signature of, e.g. json.dumps, which is only called once AFAIS in the JSON backends implementations. This is the most "brutal", naive way to acheive the desired behavior, and more elegant countersolutions are most welcome given developer input about interactions within synced_collections that I'm unaware of.

Additional context

Such control would be useful for example in Signac Projects, where the one-line job statepoint and document JSON files often become unwieldy and poorly human-readable when inspecting individual jobs. For current projects, I've relied on Project-level hooks to set the indentation on each JSON file write, but it seems like there ought to be an easier way to configure formatting which is natively supported by the stdlib json module (no "crazy" custom formatting being requested here).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions