Updated to the latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Wed, 23 Nov 2011 19:21:03 -0500
changeset 271 445fd5c6ba7c
parent 270 b612b2699a7f
child 275 f5bccf11e50e
Updated to the latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Wed Nov 09 13:59:27 2011 -0500
+++ b/playground/jsonld.js	Wed Nov 23 19:21:03 2011 -0500
@@ -2758,7 +2758,23 @@
       // replace the existing embed with a reference
       else if(embed.parent !== null)
       {
-         embed.parent[embed.key] = value['@subject'];
+         if(embed.parent[embed.key].constructor === Array)
+         {
+            var objs = embed.parent[embed.key];
+            for(var i in objs)
+            {
+               if(objs[i].constructor === Object && '@subject' in objs[i] &&
+                  objs[i]['@subject']['@iri'] === iri)
+               {
+                  objs[i] = value['@subject'];
+                  break;
+               }
+            }
+         }
+         else
+         {
+            embed.parent[embed.key] = value['@subject'];
+         }
       }
       
       // update embed entry
@@ -2783,9 +2799,11 @@
       }
       
       // iterate over keys in value
-      for(key in value)
+      var keys = Object.keys(value);
+      for(i in keys)
       {
          // skip keywords and type
+         var key = keys[i];
          if(key.indexOf('@') !== 0 && key !== ns.rdf + 'type')
          {
             // get the subframe if available
@@ -2955,7 +2973,15 @@
          }
          else
          {
-            rval.push(value);
+            // determine if value is a reference
+            var isRef = (value !== null && value.constructor === Object &&
+               '@iri' in value && value['@iri'] in embeds);
+            
+            // push any value that isn't a parentless reference
+            if(!(parent === null && isRef))
+            {
+               rval.push(value);
+            }
          }
       }
    }