Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# JetBrains IDEs
.idea/
94 changes: 83 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5156,17 +5156,89 @@ <h3>Overview</h3>
and generating a JSON-LD document in expanded form for all
<a>RDF literals</a>, <a>IRIs</a>
and <a>blank node identifiers</a>.
If the <a data-link-for="JsonLdOptions">useNativeTypes</a> flag is set to <code>true</code>,
<a>RDF literals</a> with a
<a>datatype IRI</a>
that equals <code>xsd:integer</code> or <code>xsd:double</code> are converted
to a <a>JSON numbers</a> and <a>RDF literals</a>
with a <a>datatype IRI</a>
that equals <code>xsd:boolean</code> are converted to <code>true</code> or
<code>false</code> based on their
<a>lexical form</a>
as described in
<a class="sectionRef" href="#data-round-tripping"></a>.

If the <a data-link-for="JsonLdOptions">useNativeTypes</a> flag is set
to <code>true</code>, <a>RDF literals</a> are converted to JSON values
based on their <a>datatype IRI</a> and <a>lexical form</a> as described
in <a class="sectionRef" href="#data-round-tripping"></a>.
</p>

<table class="simple">
<thead>
<th>RDF datatype</th>
<th>Values</th>
<th>JSON</th>
</thead>
<tbody>
<tr>
<th>(<em>None</em>, implying <code>xsd:string</code>)</th>
<td rowspan="2">An RDF string literal</td>
<td rowspan="2">JSON string literal</td>
</tr>
<tr>
<th><code>xsd:string</code></th>
</tr>

<tr>
<th rowspan="3"><code>xsd:integer</code></th>
<td>Whole number in the <code>[-2<sup>53</sup> + 1, 2<sup>53</sup> + 1]</code> range, representable as per [[IEEE-754-2008]]</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more constraints in the lexical form of an xsd:integer than this.

Also, while it's likely consistent with JCS/ECMAScript, such numbers also need to be representable as integers in JCS/ECMAScript. See Appendix B.
We should be careful to not mis-describe this, and just refer to XSD Datatypes 1.1 and JCS.

<td><a>JSON Number</a></td>
</tr>

<tr>
<td>Whole number out of that range</td>
<td>JSON string literal</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this needs to be serialized as a value object with @type. The integer 1e54 (1000000000000000078291540404596243842305360299886116864) is outside of that range, but the value object needs to include `"@type": "xsd:integer".

</tr>

<tr>
<td>Any other value</td>
<td>Raise an error</td>
</tr>

<tr>
<th rowspan="3"><code>xsd:double</code></th>
<td>Real number in the <code>[-2<sup>53</sup> + 1, 2<sup>53</sup> + 1]</code> range, representable as per [[IEEE-754-2008]]</td>
<td><a>JSON Number</a></td>
</tr>

<tr>
<td>Real number out of that range</td>
<td>JSON string literal</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment; the ranges should be consistent with XSD and JCS and probably shouldn't re-define the criteria.

</tr>

<tr>
<td>
Non-numeric values:

<ul>
<li><code>"NaN"^^xsd:double</code>,</li>
<li><code>"+INF"^^xsd:double</code>,</li>
<li><code>"-INF"^^xsd:double</code></li>
</ul>
</td>
<td rowspan="2">Raise an error</td>
</tr>
<tr>
<td>Any other value</td>
</tr>

<tr>
<th rowspan="3"><code>xsd:boolean</code></th>
<td><code>true</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>false</code></td>
<td><code>false</code></td>
</tr>
<tr>
<td>Any other value</td>
<td>Raise an error</td>
</tr>
</tbody>
</table>

<p>
Unless the <a data-link-for="JsonLdOptions">useRdfType</a> flag is set to true, <code>rdf:type</code>
predicates will be serialized as <code>@type</code> as long as the associated object is
either an <a>IRI</a> or <a>blank node identifier</a>.</p>
Expand Down
10 changes: 10 additions & 0 deletions tests/fromRdf-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@
"purpose": "Check list generation with rdf:first property and rdf:nil value.",
"input": "fromRdf/0026-in.nq",
"expect": "fromRdf/0026-out.jsonld"
}, {
"@id": "#t0027",
"@type": ["jld:PositiveEvaluationTest", "jld:FromRDFTest"],
"name": "native types flag set to true is ignored if the number provided is invalid in JSON",
"purpose": "Literals with datatype xsd:boolean, xsd:integer, and xsd:double are serialized using native scalar values if possible",
"option": {
"useNativeTypes": true
},
"input": "fromRdf/0027-in.nq",
"expect": "fromRdf/0027-out.jsonld"
}, {
"@id": "#tdi01",
"@type": [ "jld:PositiveEvaluationTest", "jld:FromRDFTest" ],
Expand Down
5 changes: 5 additions & 0 deletions tests/fromRdf/0027-in.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<http://example.com/Subj1> <http://example.com/prop> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<http://example.com/Subj1> <http://example.com/prop> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<http://example.com/Subj1> <http://example.com/prop> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.com/Subj1> <http://example.com/prop> "1.1"^^<http://www.w3.org/2001/XMLSchema#decimal> .
<http://example.com/Subj1> <http://example.com/prop> "+INF"^^<http://www.w3.org/2001/XMLSchema#double> .
12 changes: 12 additions & 0 deletions tests/fromRdf/0027-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"@id": "http://example.com/Subj1",
"http://example.com/prop": [
{ "@value": true },
{ "@value": false },
{ "@value": 1 },
{ "@value": "1.1", "@type": "http://www.w3.org/2001/XMLSchema#decimal"},
{ "@value": "+INF", "@type": "http://www.w3.org/2001/XMLSchema#double"}
]
}
]
Loading