@@ -23,7 +23,8 @@ const {
23
23
expandIri : _expandIri ,
24
24
getContextValue : _getContextValue ,
25
25
isKeyword : _isKeyword ,
26
- process : _processContext
26
+ process : _processContext ,
27
+ processingMode : _processingMode
27
28
} = require ( './context' ) ;
28
29
29
30
const {
@@ -289,6 +290,8 @@ api.expand = ({
289
290
'Invalid JSON-LD syntax; only strings may be language-tagged.' ,
290
291
'jsonld.SyntaxError' ,
291
292
{ code : 'invalid language-tagged value' , element : rval } ) ;
293
+ } else if ( _processingMode ( activeCtx , 1.1 ) && types . includes ( '@json' ) && types . length === 1 ) {
294
+ // Any value of @value is okay if @type: @json
292
295
} else if ( ! types . every ( t =>
293
296
( _isAbsoluteIri ( t ) && ! ( _isString ( t ) && t . indexOf ( '_:' ) === 0 ) ||
294
297
_isEmptyObject ( t ) ) ) ) {
@@ -494,16 +497,7 @@ function _expandObject({
494
497
'jsonld.SyntaxError' , { code : 'invalid @graph value' , value} ) ;
495
498
}
496
499
497
- // @value must not be an object or an array (unless framing)
498
500
if ( expandedProperty === '@value' ) {
499
- if ( ( _isObject ( value ) || _isArray ( value ) ) && ! options . isFrame ) {
500
- throw new JsonLdError (
501
- 'Invalid JSON-LD syntax; "@value" value must not be an ' +
502
- 'object or an array.' ,
503
- 'jsonld.SyntaxError' ,
504
- { code : 'invalid value object value' , value} ) ;
505
- }
506
-
507
501
_addValue (
508
502
expandedParent , '@value' , value , { propertyIsArray : options . isFrame } ) ;
509
503
continue ;
@@ -753,6 +747,20 @@ function _expandObject({
753
747
} ) ;
754
748
}
755
749
750
+ // @value must not be an object or an array (unless framing) or if @type is @json
751
+ if ( '@value' in element ) {
752
+ const value = element [ '@value' ] ;
753
+ if ( element [ '@type' ] === '@json' && _processingMode ( activeCtx , 1.1 ) ) {
754
+ // Sllow any value, to be verified when the object is fully expanded and the @type is @json.
755
+ } else if ( ( _isObject ( value ) || _isArray ( value ) ) && ! options . isFrame ) {
756
+ throw new JsonLdError (
757
+ 'Invalid JSON-LD syntax; "@value" value must not be an ' +
758
+ 'object or an array.' ,
759
+ 'jsonld.SyntaxError' ,
760
+ { code : 'invalid value object value' , value} ) ;
761
+ }
762
+ }
763
+
756
764
// expand each nested key
757
765
for ( const key of nests ) {
758
766
const nestedValues = _isArray ( element [ key ] ) ? element [ key ] : [ element [ key ] ] ;
0 commit comments