@@ -23,7 +23,8 @@ const {
2323 expandIri : _expandIri ,
2424 getContextValue : _getContextValue ,
2525 isKeyword : _isKeyword ,
26- process : _processContext
26+ process : _processContext ,
27+ processingMode : _processingMode
2728} = require ( './context' ) ;
2829
2930const {
@@ -289,6 +290,8 @@ api.expand = ({
289290 'Invalid JSON-LD syntax; only strings may be language-tagged.' ,
290291 'jsonld.SyntaxError' ,
291292 { 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
292295 } else if ( ! types . every ( t =>
293296 ( _isAbsoluteIri ( t ) && ! ( _isString ( t ) && t . indexOf ( '_:' ) === 0 ) ||
294297 _isEmptyObject ( t ) ) ) ) {
@@ -494,16 +497,7 @@ function _expandObject({
494497 'jsonld.SyntaxError' , { code : 'invalid @graph value' , value} ) ;
495498 }
496499
497- // @value must not be an object or an array (unless framing)
498500 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-
507501 _addValue (
508502 expandedParent , '@value' , value , { propertyIsArray : options . isFrame } ) ;
509503 continue ;
@@ -753,6 +747,20 @@ function _expandObject({
753747 } ) ;
754748 }
755749
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+
756764 // expand each nested key
757765 for ( const key of nests ) {
758766 const nestedValues = _isArray ( element [ key ] ) ? element [ key ] : [ element [ key ] ] ;
0 commit comments