goofballLogic / ld-query

Querying JSON-LD
MIT License
20 stars 6 forks source link

Search for @id only matches top level properties #30

Open goofballLogic opened 4 years ago

goofballLogic commented 4 years ago

When searching in a document for a node with arbitrary identity (e.g. [@id=http://xyz.com]) this will only match if the identified node is at the top of the queryied JSON.

goofballLogic commented 4 years ago

See https://codepen.io/goofballLogic/pen/VwYRRjx for example

var doc = [{
  "@id": "http://test.com/1",
  "http://test.com/name": [{
    "@value": "hello"
  }],
  "http://test.com/nested": [{
    "@id": "http://test.com/2",
    "http://test.com/name": [{
      "@value": "world"
    }]
  }]
}];

var docQuery = LD(doc, {});
var thing1 = docQuery.query("[@id=http://test.com/1]");
var thing2 = docQuery.query("[@id=http://test.com/2]");

output.textContent = 
  docQuery // object
  + " " + thing1 // object
  + " " + thing2 // null
  ;