@@ -3184,10 +3184,10 @@ <h3>Object to RDF Conversion</h3>
3184
3184
< h3 > Overview</ h3 >
3185
3185
3186
3186
< p > < tref title ="value object "> Value objects</ tref > are transformed to
3187
- < tref title ="RDF literal "> RDF literals</ tref > as defined in the section
3188
- < a href ="#data-round-tripping "> Data Round Tripping</ a > whereas
3189
- < tref title ="node object "> node objects</ tref > are transformed to
3190
- < tref title ="IRI "> IRIs</ tref > or
3187
+ < tref title ="RDF literal "> RDF literals</ tref > as described in
3188
+ < a class =" sectionRef " href ="#data-round-tripping "> Data Round Tripping</ a >
3189
+ whereas < tref title ="node object "> node objects</ tref > are transformed
3190
+ to < tref title ="IRI "> IRIs</ tref > or
3191
3191
< tref title ="blank node identifier "> blank node identifiers</ tref > .</ p >
3192
3192
</ section >
3193
3193
@@ -3208,18 +3208,30 @@ <h3>Algorithm</h3>
3208
3208
< code > @type</ code > member of < i > item</ i > or < code > null</ code > if
3209
3209
< i > item</ i > does not have such a member.</ li >
3210
3210
< li > If < i > value</ i > is < tref > true</ tref > or
3211
- < tref > false</ tref > , set < i > value</ i > to its
3212
- < tref > canonical lexical form</ tref > as defined
3213
- in the section < a href ="#data-round-tripping "> Data Round Tripping</ a > .
3211
+ < tref > false</ tref > , set < i > value</ i > to the < tref > string</ tref >
3212
+ < code > true</ code > or < code > false</ code > which is the
3213
+ < tref > canonical lexical form</ tref > as described in
3214
+ < a class ="sectionRef " href ="#data-round-tripping "> Data Round Tripping</ a >
3214
3215
If < i > datatype</ i > is < tref > null</ tref > , set it to
3215
3216
< code > xsd:boolean</ code > .</ li >
3216
- < li > Otherwise, if < i > value</ i > is a < tref > number</ tref > , then set
3217
- < i > value</ i > to its < tref > canonical lexical form</ tref > as defined
3218
- in the section < a href ="#data-round-tripping "> Data Round Tripping</ a > .
3219
- If < i > datatype</ i > is < tref > null</ tref > , set it to either
3220
- < code > xsd:integer</ code > or < code > xsd:double</ code > , depending
3221
- on if the value contains a fractional and/or an exponential
3222
- component.</ li >
3217
+ < li > Otherwise, if < i > value</ i > is a < tref > number</ tref > with fractions
3218
+ or < i > value</ i > is a < tref > number</ tref > and < i > datatype</ i > equals
3219
+ < code > xsd:double</ code > , convert < i > value</ i > to a
3220
+ < tref > string</ tref > in < tref > canonical lexical form</ tref > of
3221
+ an < code > xsd:double</ code > as defined in [[!XMLSCHEMA11-2]]
3222
+ and described in
3223
+ < a class ="sectionRef " href ="#data-round-tripping "> Data Round Tripping</ a > .
3224
+ If < i > datatype</ i > is < tref > null</ tref > , set it to
3225
+ < code > xsd:double</ code > .</ li >
3226
+ < li > Otherwise, if < i > value</ i > is a < tref > number</ tref > without fractions
3227
+ or < i > value</ i > is a < tref > number</ tref > and < i > datatype</ i > equals
3228
+ < code > xsd:integer</ code > , convert < i > value</ i > to a
3229
+ < tref > string</ tref > in < tref > canonical lexical form</ tref > of
3230
+ an < code > xsd:integer</ code > as defined in [[!XMLSCHEMA11-2]]
3231
+ and described in
3232
+ < a class ="sectionRef " href ="#data-round-tripping "> Data Round Tripping</ a > .
3233
+ If < i > datatype</ i > is < tref > null</ tref > , set it to
3234
+ < code > xsd:integer</ code > .</ li >
3223
3235
< li > Otherwise, if < i > datatype</ i > is < tref > null</ tref > , set it to
3224
3236
< code > xsd:string</ code > or < code > rdf:langString</ code > , depending on if
3225
3237
item has an < code > @language</ code > member.</ li >
@@ -3326,7 +3338,8 @@ <h3>Overview</h3>
3326
3338
that equals < code > xsd:boolean</ code > are converted to < tref > true</ tref > or
3327
3339
< tref > false</ tref > based on their
3328
3340
< tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form "> lexical form</ tref >
3329
- as defined in the section < a href ="#data-round-tripping "> Data Round Tripping</ a > .</ p >
3341
+ as described in
3342
+ < a class ="sectionRef " href ="#data-round-tripping "> Data Round Tripping</ a > .</ p >
3330
3343
</ section >
3331
3344
3332
3345
< section >
@@ -3502,7 +3515,8 @@ <h3>Overview</h3>
3502
3515
that equals < code > xsd:boolean</ code > are converted to < tref > true</ tref > or
3503
3516
< tref > false</ tref > based on their
3504
3517
< tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form "> lexical form</ tref >
3505
- as defined in the section < a href ="#data-round-tripping "> Data Round Tripping</ a > .</ p >
3518
+ as described in
3519
+ < a class ="sectionRef " href ="#data-round-tripping "> Data Round Tripping</ a > .</ p >
3506
3520
</ section >
3507
3521
3508
3522
< section >
@@ -3537,17 +3551,19 @@ <h3>Algorithm</h3>
3537
3551
of < i > value</ i > equals < code > xsd:boolean</ code > , set
3538
3552
< i > converted value</ i > to < tref > true</ tref > if the
3539
3553
< tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form "> lexical form</ tref >
3540
- of < i > value</ i > matches < code > true</ code > , or < code > false</ code > if
3541
- it matches < code > false</ code > . If it matches neither, set < i > type </ i > to
3542
- < code > xsd:boolean</ code > .</ li >
3554
+ of < i > value</ i > matches < code > true</ code > , or < tref > false</ tref >
3555
+ if it matches < code > false</ code > . If it matches neither,
3556
+ set < i > type </ i > to < code > xsd:boolean</ code > .</ li >
3543
3557
< li > Otherwise, if the
3544
3558
< tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri "> datatype IRI</ tref >
3545
3559
of < i > value</ i > equals < code > xsd:integer</ code > or
3546
- < code > xsd:double</ code > , try to convert the literal to a
3547
- < tref title ="number "> JSON number</ tref > . If the conversion is
3548
- successful, store the result in < i > converted value</ i > ; otherwise, set < i > type</ i > to
3549
- the < tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri "> datatype IRI</ tref >
3550
- of < i > value</ i > .</ li >
3560
+ < code > xsd:double</ code > and its
3561
+ < tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form "> lexical form</ tref >
3562
+ is a valid < code > xsd:integer</ code > or < code > xsd:double</ code >
3563
+ according [[!XMLSCHEMA11-2]], set < i > converted value</ i >
3564
+ to the result of converting the
3565
+ < tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form "> lexical form</ tref >
3566
+ to a JSON < tref > number</ tref > .</ li >
3551
3567
</ ol >
3552
3568
</ li >
3553
3569
< li > Otherwise, if < i > value</ i > is a
@@ -3572,19 +3588,23 @@ <h3>Algorithm</h3>
3572
3588
< section >
3573
3589
< h2 > Data Round Tripping</ h2 >
3574
3590
3575
- < p > When < a href ="#rdf-conversion "> converting JSON-LD to RDF</ a > JSON-native types such as
3576
- < em > numbers</ em > and < em > booleans</ em > are automatically coerced to
3577
- < code > xsd:integer</ code > , < code > xsd:double</ code > , or < code > xsd:boolean</ code > .
3578
- Implementers MUST ensure that the result is in < tref > canonical lexical form</ tref > . A
3579
- < tdef > canonical lexical form</ tdef > is a set of literals from among the valid set of literals for
3580
- a datatype such that there is a one-to-one mapping between the < tref > canonical lexical form</ tref >
3581
- and a value in the value space as defined in [[!XMLSCHEMA11-2]]. In other words, every
3582
- value MUST be converted to a deterministic < tref > string</ tref > representation.</ p >
3583
-
3584
- < p > The canonical lexical form of an < em > integer</ em > , i.e., a number without fractions
3585
- or a number coerced to < code > xsd:integer</ code > , is a finite-length sequence of decimal
3586
- digits (< code > 0-9</ code > ) with an optional leading minus sign; leading zeros are prohibited.
3587
- To convert the number in JavaScript, implementers can use the following snippet of code:</ p >
3591
+ < p > When < a href ="#convert-to-rdf-algorithm "> converting JSON-LD to RDF</ a >
3592
+ JSON-native < tref title ="number "> numbers</ tref > are automatically
3593
+ type-coerced to < code > xsd:integer</ code > or < code > xsd:double</ code >
3594
+ depending on whether the < tref > number</ tref > has fractions or not and
3595
+ the boolean values < tref > true</ tref > and < tref > false</ tref > are
3596
+ coerced to < code > xsd:boolean</ code > . The numeric or boolean value
3597
+ itself is converted to < tdef > canonical lexical form</ tdef > , i.e., a
3598
+ deterministic string representation as defined in
3599
+ [[!XMLSCHEMA11-2]].</ p >
3600
+
3601
+ < p > The < tref > canonical lexical form</ tref > of an < em > integer</ em > , i.e.,
3602
+ a < tref > number</ tref > without fractions or a < tref > number</ tref > coerced
3603
+ to < code > xsd:integer</ code > , is a finite-length sequence of decimal
3604
+ digits (< code > 0-9</ code > ) with an optional leading minus sign; leading
3605
+ zeros are prohibited. In JavaScript, implementers can use the following
3606
+ snippet of code to convert an integer to
3607
+ < tref > canonical lexical form</ tref > :</ p >
3588
3608
3589
3609
< pre class ="example " data-transform ="updateExample "
3590
3610
title ="Sample integer serialization implementation in JavaScript ">
@@ -3593,21 +3613,27 @@ <h2>Data Round Tripping</h2>
3593
3613
-->
3594
3614
</ pre >
3595
3615
3596
- < p > The canonical lexical form of a < em > double</ em > , i.e., a number with fractions
3597
- or a number coerced to < code > xsd:double</ code > , consists of a mantissa followed by the
3598
- character "E", followed by an exponent. The mantissa MUST be a decimal number. The exponent
3599
- MUST be an integer. Leading zeros and a preceding plus sign (< code > +</ code > ) are prohibited
3600
- in the exponent. If the exponent is zero, it must be indicated by < code > E0</ code > .
3601
- For the mantissa, the preceding optional plus sign is prohibited and the decimal point is
3602
- required. Leading and trailing zeros are prohibited subject to the following: number
3603
- representations must be normalized such that there is a single digit which is non-zero to the
3604
- left of the decimal point and at least a single digit to the right of the decimal point unless
3605
- the value being represented is zero. The canonical representation for zero is < code > 0.0E0</ code > .
3606
- < code > xsd:double</ code > 's value space is defined by the IEEE double-precision 64-bit
3607
- floating point type [[!IEEE-754-1985]]; in JSON-LD the mantissa is rounded to 15 digits after the
3608
- decimal point.</ p >
3609
-
3610
- < p > To convert the number in JavaScript, implementers can use the following snippet of code:</ p >
3616
+ < p > The < tref > canonical lexical form</ tref > of a < em > double</ em > , i.e., a
3617
+ < tref > number</ tref > with fractions or a < tref > number</ tref > coerced to
3618
+ < code > xsd:double</ code > , consists of a mantissa followed by the
3619
+ character < code > E</ code > , followed by an exponent. The mantissa is a
3620
+ decimal number and the exponent is an integer. Leading zeros and a
3621
+ preceding plus sign (< code > +</ code > ) are prohibited in the exponent.
3622
+ If the exponent is zero, it is indicated by < code > E0</ code > . For the
3623
+ mantissa, the preceding optional plus sign is prohibited and the
3624
+ decimal point is required. Leading and trailing zeros are prohibited
3625
+ subject to the following: number representations must be normalized
3626
+ such that there is a single digit which is non-zero to the left of
3627
+ the decimal point and at least a single digit to the right of the
3628
+ decimal point unless the value being represented is zero. The
3629
+ canonical representation for zero is < code > 0.0E0</ code > .
3630
+ < code > xsd:double</ code > 's value space is defined by the IEEE
3631
+ double-precision 64-bit floating point type [[!IEEE-754-1985]] whereas
3632
+ the value space of JSON < tref title ="number "> numbers</ tref > is not
3633
+ specified; when converting JSON-LD to RDF the mantissa is rounded to
3634
+ 15 digits after the decimal point. In JavaScript, implementers
3635
+ can use the following snippet of code to convert a double to
3636
+ < tref > canonical lexical form</ tref > :</ p >
3611
3637
3612
3638
< pre class ="example " data-transform ="updateExample "
3613
3639
title ="Sample floating point number serialization implementation in JavaScript ">
@@ -3616,14 +3642,30 @@ <h2>Data Round Tripping</h2>
3616
3642
-->
3617
3643
</ pre >
3618
3644
3619
- < p > The canonical lexical form of the < em > boolean</ em > values < tref > true</ tref > and < tref > false</ tref >
3620
- are the strings < code > true</ code > and < code > false</ code > .</ p >
3621
-
3622
- < p > When JSON-native < tref > number</ tref > s, are type coerced, lossless data round-tripping can not
3623
- be guaranteed as rounding errors might occur. Additionally, only literals typed as
3624
- < code > xsd:integer</ code > , < code > xsd:double</ code > , and < code > xsd:boolean</ code > are
3625
- automatically converted back to their JSON-native counterparts in when
3626
- < a href ="#rdf-conversion "> converting from RDF</ a > .</ p >
3645
+ < p > The < tref > canonical lexical form</ tref > of the < em > boolean</ em >
3646
+ values < tref > true</ tref > and < tref > false</ tref > are the strings
3647
+ < code > true</ code > and < code > false</ code > .</ p >
3648
+
3649
+ < p > When JSON-native < tref title ="number "> numbers</ tref > , are converted
3650
+ to RDF, lossless data round-tripping can not be guaranteed as rounding
3651
+ errors might occur. When converting
3652
+ < a href ="#convert-from-rdf-algorithm "> RDF to JSON-LD</ a > , similar
3653
+ rounding errors might occur. Furthermore, the datatype or the lexical
3654
+ representation might be lost. An < code > xsd:double</ code > with a value
3655
+ of < code > 2.0</ code > will, e.g., result in an < code > xsd:integer</ code >
3656
+ with a value of < code > 2</ code > in < tref > canonical lexical form</ tref >
3657
+ when converted from RDF to JSON-LD and back to RDF.</ p >
3658
+
3659
+ < p > To ensure lossless round-tripping the
3660
+ < a href ="#convert-from-rdf-algorithm "> Converting from RDF algorithm</ a >
3661
+ specifies an < i > use native types</ i > flag which controls whether
3662
+ < tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-literal "> RDF literals</ tref >
3663
+ with a < tref href ="http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri "> datatype IRI</ tref >
3664
+ equal to < code > xsd:integer</ code > , < code > xsd:double</ code > , or
3665
+ < code > xsd:boolean</ code > are converted to their JSON-native
3666
+ counterparts. If the < i > use native types</ i > flag is set to
3667
+ < tref > false</ tref > , all literals remain in their original string
3668
+ representation.</ p >
3627
3669
3628
3670
< p > Some JSON serializers, such as PHP's native implementation in some versions,
3629
3671
backslash-escape the forward slash character. For example, the value
0 commit comments