{"record":{"id":"488c999f368dacdc","repo":"cayleygraph/cayley","slug":"can-not-parse-json-ld-identifier-v","errorCode":null,"errorMessage":"can not parse JSON-LD identifier: %#v","messagePattern":"can not parse JSON-LD identifier: %#v","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/linkedql/registry.go","lineNumber":263,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"blank node ID must start with \\\"_:\\\"\")\n\t}\n\treturn quad.BNode(s[2:]), nil\n}\n\nfunc parseIRI(s string) (quad.IRI, error) {\n\treturn quad.IRI(s), nil\n}\n\nfunc parseIdentifier(s string) (quad.Value, error) {\n\tbnode, err := parseBNode(s)\n\tif err == nil {\n\t\treturn bnode, nil\n\t}\n\tiri, err := parseIRI(s)\n\tif err == nil {\n\t\treturn iri, nil\n\t}\n\treturn nil, fmt.Errorf(\"can not parse JSON-LD identifier: %#v\", s)\n}\n\nfunc parseIdentifierString(a interface{}) (string, error) {\n\tm, ok := a.(map[string]interface{})\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type: %T\", a)\n\t}\n\tid, ok := m[\"@id\"].(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"expected a @id key\")\n\t}\n\treturn id, nil\n}\n\nfunc parseLiteral(a interface{}) (quad.Value, error) {\n\tswitch a := a.(type) {\n\tcase string:\n\t\treturn quad.String(a), nil","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/linkedql/registry.go#L245-L281","documentation":"parseIdentifier is the last resort when converting a JSON-LD identifier string: it first tries parseBNode (\"_:\"-prefixed blank nodes) and then parseIRI (any other string is accepted as an IRI), so in practice this error fires when the input is not a string at all, or when the fallback path is handed an empty/invalid value. It signals that the value cannot be interpreted as any JSON-LD identifier form the registry supports.","triggerScenarios":"BuildIdentifier or parseValue receiving a value that is neither a map with \"@id\" nor a usable string — e.g. a number, bool, nil, or array passed where an identifier (string or {\"@id\": ...}) is expected in a step document.","commonSituations":"Programmatic construction of LinkedQL steps where a variable of the wrong type is interpolated into an @id field; JSON decoding quirks where numbers or nulls end up in identifier positions; templating errors that render empty strings.","solutions":["Ensure the identifier is a string: either an absolute IRI (\"http://...\") or a blank node (\"_:label\").","If the value is a node object, wrap it as {\"@id\": \"<iri-or-bnode>\"} so parseIdentifierString extracts the id first.","Convert non-string scalars explicitly (fmt.Sprintf or a serializer) before placing them in identifier positions.","Log %#v of the offending value and trace which step field supplied it."],"exampleFix":"// before\n{\"@id\": 42}\n// after\n{\"@id\": \"http://example.com/entity/42\"}","handlingStrategy":"type-guard","validationCode":"func isUsableIdentifier(v interface{}) bool {\n  switch t := v.(type) {\n  case string:\n    return t != \"\" && (strings.HasPrefix(t, \"_:\") || strings.Contains(t, \":\"))\n  case map[string]interface{}:\n    _, ok := t[\"@id\"].(string)\n    return ok\n  }\n  return false\n}","typeGuard":"func asIdentifier(v interface{}) (string, bool) {\n  switch t := v.(type) {\n  case string:\n    return t, true\n  case map[string]interface{}:\n    id, ok := t[\"@id\"].(string)\n    return id, ok\n  }\n  return \"\", false\n}","tryCatchPattern":"id, err := linkedql.BuildIdentifier(raw)\nif err != nil {\n  if strings.Contains(err.Error(), \"can not parse JSON-LD identifier\") {\n    log.Printf(\"bad identifier %#[1]v in step field\", raw)\n    return fmt.Errorf(\"identifier field requires IRI or _:bnode string, got %T\", raw)\n  }\n  return err\n}","preventionTips":["Validate that identifier fields contain only strings or {\"@id\": string} maps before submission.","Avoid interpolating raw scalars (numbers, bools) into @id positions.","Share one identifier-construction helper across all step-building code."],"tags":["go","json-ld","identifier","parsing"],"backgroundTag":"invalid-identifier","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}