Skip to content

Quote identifier-shaped numbers (e.g. PDB code 6E72) in JSON output - #445

Open
barlowa124 wants to merge 1 commit into
project-gemmi:masterfrom
barlowa124:mmjson-numberlike-id-444
Open

barlowa124 wants to merge 1 commit into
project-gemmi:masterfrom
barlowa124:mmjson-numberlike-id-444

Conversation

@barlowa124

Copy link
Copy Markdown

Closes #444.

mmJSON (and default CIF-JSON) output wrote _entry.id 6E72 as a bare JSON value, which every JSON parser reads as the float 6e72. Real mmCIF files write such codes unquoted, so the quoting flag cannot disambiguate them.

JsonWriter::write_value now quotes tokens shaped digits + uppercase E + digits (no decimal point, no sign), next to the existing 012 exception. This matches the identifier shape of PDB codes (6E72, 7E57) while leaving real numeric tokens alone: 1.2E3, 2e4, -3E5, and 2E+6 still emit as JSON numbers.

Tested via a new case in test_cif_json.py (unfixed code produced a float, fixed produces the string) and the full suite passes on Python 3.13 (python -m unittest discover in tests/).

A token like 6E72 is a valid CIF number (6e72) but also a PDB entry ID,
and real mmCIF files write _entry.id unquoted. Emitting it bare produced
JSON that parses to a float (or Infinity in some readers), changing the
value's type. PDB codes such as 6E72 and 7E57 hit this.

A new entry in the number-vs-string check quotes values of the form
digits + E + digits with no decimal point or sign, alongside the existing
012 exception. Real numeric tokens (1.2E3, 2e4, -3E5, 2E+6) still emit
as JSON numbers.

Closes project-gemmi#444.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

mmJSON converter treats entry IDs with letter "E" in them as exponential float

1 participant