Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Inline contexts that try to redefine @context now raise an error. Fixes [expand#ter56](https://w3c.github.io/json-ld-api/tests/expand-manifest.html#ter56) and [toRdf#ter56](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#ter56).
- When using native types, values of `xsd:boolean` and `xsd:integer` are now properly converted. Fixes [fromRdf#t0027](https://w3c.github.io/json-ld-api/tests/fromRdf-manifest.html#t0027).
- Numbers with 0 as fractional part now parse to an `xsd:integer` instead of `xsd:double`. Fixes [toRdf#ttn02](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#ttn02).
- Zeros are now truncated for numeric values with negative exponent.

## 3.1.0 - 2026-06-19

Expand Down
2 changes: 1 addition & 1 deletion lib/pyld/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -6388,7 +6388,7 @@ def _is_double(v):

def _canonicalize_double(value: float) -> str:
"""Convert a float value to canonical lexical form of `xsd:double`."""
return re.sub(r'(\d)0*E\+?0*(\d)', r'\1E\2', (f'{value:1.15E}'))
return re.sub(r'(\d)0*E\+?(-)?0*(\d)', r'\1E\2\3', (f'{value:1.15E}'))


def _is_numeric(v):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,18 @@ def test_fractional(self):
nquads = jsonld.to_rdf(input, options={'format': 'application/n-quads'})
assert nquads == expected

# Issue 175
def test_truncate_zeros_with_negative_exponent_numbers(self):
"""
Numeric values with negative exponent should truncate zeros
"""
input = { "ex:value": 0.97 }

expected = '_:b0 <ex:value> "9.7E-1"^^<http://www.w3.org/2001/XMLSchema#double> .\n'

nquads = jsonld.to_rdf(input, options={'format': 'application/n-quads'})
assert nquads == expected

class TestFromRDF:
def test_compound_literal_direction_without_language(self):
"""
Expand Down
Loading