Skip to content

Conversation

@mikee47
Copy link
Owner

@mikee47 mikee47 commented Feb 11, 2025

This PR addresses issue #60 to enable variations in how JSON is generated.

An extensible ExportOptions structure has been added to all createExportStream and exportToStream methods to allow customisation of output. It contains three flags:

pretty

This replaces the global Json::format.pretty flag to allow control on a per-stream basis.

useName

Set this flag to include the object name in the output. For example:

"int_array": [13,28,39,40]

Default behaviour excludes the name:

[13,28,39,40]

This also works for the database using the name defined in the schema.

asObject

Outputs the entire object definition:

{
  "int_array": [13,28,39,40]
}

The useName flag is implicit in this option and does not need to be set as well.

NB. I decided against using an enum to try and simplify the interface.

  • Update README

Allows `pretty` to be configured on a per-stream basis.
Include support for output options at database level
@mikee47
Copy link
Owner Author

mikee47 commented Feb 11, 2025

@pljakobs I'd welcome your thoughts on this reworking of the export options. I've removed the ability to override the object name and emit raw content as there's currently no use case for them.

@mikee47 mikee47 merged commit 076608b into develop Feb 12, 2025
@mikee47 mikee47 deleted the feature/export-options-2 branch February 12, 2025 10:49
slaff pushed a commit to SmingHub/Sming that referenced this pull request Feb 12, 2025
Fix handling of `name=value` selectors for root arrays [#64](mikee47/ConfigDB#64)

Support conversion of named selector into range [#65](mikee47/ConfigDB#65)

    * Allows item deletion using  `"x[name=object 1]": []` syntax

Add `ExportOptions` [#68](mikee47/ConfigDB#68)

    Allows `pretty` to be configured on a per-stream basis.
    Add optional `useName`, `asObject` flags.
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

Successfully merging this pull request may close these issues.

2 participants