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

Make FluxTable and FluxRecord json serializable #311

Closed
russorat opened this issue Aug 18, 2021 · 2 comments · Fixed by #320
Closed

Make FluxTable and FluxRecord json serializable #311

russorat opened this issue Aug 18, 2021 · 2 comments · Fixed by #320
Labels
enhancement New feature or request
Milestone

Comments

@russorat
Copy link
Contributor

it would be really handy for debugging if the objects returned from the write_api were json serializable by default (FluxTable and FluxRecord). this would avoid the need to do stuff like json.dumps(record.__dict__)

I think for this you would simply need to supply a toJSON function in those classes.

@russorat russorat added the enhancement New feature or request label Aug 18, 2021
@bednar
Copy link
Contributor

bednar commented Aug 18, 2021

@russorat thanks for suggestion to enhancement, I will take a look.

@bednar
Copy link
Contributor

bednar commented Aug 24, 2021

@russorat, unfortunately the toJSON is not enough. Because json.dumps needs to have defined a default parameter that returns a serializable object.

I have prepared a FluxStructureEncoder encoder which simplifies usage of json encoder to:

import json
from influxdb_client.client.flux_table import FluxStructureEncoder

output = json.dumps(tables, cls=FluxStructureEncoder, indent=2)
print(output)

@bednar bednar added this to the 1.21.0 milestone Aug 31, 2021
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