Repository navigation
Enable storage of maximally compact JSON-encoded data (such as fit results) - #973
Merged
Merged
Conversation
…pression of JSON output on demand and extend test cases accordingly
JanWeldert
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PISA currently only exposes the
indentparameter ofsimplejson.dumps()viautils.jsons.to_json()and thereforeutils.fileio.to_file(), which has a default value of2for pretty (easily readable and editable) JSON files. However, the minimal size of the output JSON-encoded data is achieved by combining the argumentsindent=Noneseparators=(',', ':')In particular, according to the above simplejson docs, no value for
indentresults in separators without any surrounding whitespace. Hence, PISA itself is unable to produce the most compact JSON which is functionally identical to the original (extra steps such aspython -m json.tool <input.json> <output.json> --compactwould be required). This is desirable for large-scale analyses with many (large) fits though.Solution
Add an intuitive
compactifyparameter toutils.jsons.to_json(), which if set toTrue(default remainsFalsethough, so precedence is given to "prettiness") overrides anyindentchoice and results in calling ofsimplejson.dumps()withseparators=(',', ':')andindent=None. I have also extended the roundtrip unit test such that it makes use ofcompactifyand checks that file sizes are indeed reduced (where this is expected).Impact
Further remarks
The pull request also removes the spurious
outfileargument/second positional argument accidentally passed tojson.dumps()inpisa/pisa/utils/jsons.py
Line 256 in bbd8d07
**kwargsin the signature ofdumps()).