feat: add to_json convenience API - #15
Conversation
alesanfra
left a comment
There was a problem hiding this comment.
Hi @micheal000010000-hub, nice contribution! The PR is already in great shape. There's just one minor adjustment needed regarding the default indentation value.
In Python, when a keyword argument is nullable, we generally expect the same behavior whether the argument is omitted entirely or explicitly passed as None. Setting 2 as the default indentation feels a bit opinionated (e.g., why 2 instead of 4 or 1?).
As noted in my inline suggestion, I'd recommend matching the behavior of the standard json module to keep things as conventional and neutral as possible. Let me know if that makes sense to you!
| /// "age": 30 | ||
| /// } | ||
| #[pyfunction] | ||
| #[pyo3(signature = (s, *, strict=true, expand_paths=None, indent=2))] |
There was a problem hiding this comment.
I'm not a fan of the default indent set to 2, I would match the behavior of the json module, it feels more natural IMHO.
| #[pyo3(signature = (s, *, strict=true, expand_paths=None, indent=2))] | |
| #[pyo3(signature = (s, *, strict=true, expand_paths=None, indent=None))] |
|
Thanks for the review — that makes sense. I agree that matching Python’s standard I’ve updated the implementation to default Review the diff and let me know |
Description
Adds a convenience API
toons.to_json()for converting TOON strings directly to JSON strings.This reduces boilerplate for a common interoperability workflow where users currently need to manually combine TOONS parsing with Python’s
jsonmodule:The new helper preserves existing parsing behavior and options (
strict,expand_paths) while providing a simpler one-step API.Changes
toons.to_json()public API insrc/lib.rstoons.pyiindent=None)Type of Change
Related Issues
N/A
Testing
Baseline (
main):pytest # 747 passed, 1 xfailedFeature branch:
Results:
Checklist