Materials-Consortia / Materials-Consortia/optimade-python-tools
Option for pretty indented json output
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 91
- Forks
- 54
- PR merge metrics
- No merged PRs in 30d
Description
When testing things and debugging, it would sometimes be quite helpful if there was a config option to turn on nicely indented json output. E.g., as you get from Pythons json module via the optional parameters sort_keys and indent to json.dumps.
I started looking into if I could prepare a quick PR myself, but realized it wasn't completely trivial due to the way the body is handled in chunks in optimade/server/middleware.py. A quick (but somewhat ugly) implementation would be to insert something like
if CONFIG.pretty_output:
content_json = json.loads(content)
content = json.dumps(content_json, sort_keys=True, indent=4)
but due to the chunking processing I didn't yet find the right place to insert this.
Nevertheless, before I spend more time on it, it would be good to know if others also see this option as useful / if the PR would be welcomed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading optimade/server/middleware.py, focusing on how response bodies are handled in chunks and where JSON content is assembled. Check how CONFIG options are defined and consumed. Done means an opt-in configuration setting produces sorted, indented JSON output without breaking chunked response handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100