{"record":{"id":"147c92355a43793e","repo":"cayleygraph/cayley","slug":"can-not-parse-v-as-a-literal","errorCode":null,"errorMessage":"can not parse %#v as a literal","messagePattern":"can not parse %#v as a literal","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/linkedql/registry.go","lineNumber":302,"sourceCode":"\tcase float64:\n\t\ti := int64(a)\n\t\tif a == float64(i) {\n\t\t\treturn quad.Int(i), nil\n\t\t}\n\t\treturn quad.Float(a), nil\n\tcase bool:\n\t\treturn quad.Bool(a), nil\n\tcase map[string]interface{}:\n\t\tif val, ok := a[\"@value\"].(string); ok {\n\t\t\tif lang, ok := a[\"@language\"].(string); ok {\n\t\t\t\treturn quad.LangString{Value: quad.String(val), Lang: lang}, nil\n\t\t\t}\n\t\t\tif typ, ok := a[\"@type\"].(string); ok {\n\t\t\t\treturn quad.TypedString{Value: quad.String(val), Type: quad.IRI(typ)}, nil\n\t\t\t}\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"can not parse %#v as a literal\", a)\n}\n\nfunc parseValue(a interface{}) (quad.Value, error) {\n\tidentifierString, err := parseIdentifierString(a)\n\tif err == nil {\n\t\tidentifier, err := parseIdentifier(identifierString)\n\t\tif err == nil {\n\t\t\treturn identifier, nil\n\t\t}\n\t}\n\tlit, err := parseLiteral(a)\n\tif err == nil {\n\t\treturn lit, nil\n\t}\n\treturn nil, fmt.Errorf(\"can not parse JSON-LD value: %#v\", a)\n}\n","sourceCodeStart":284,"sourceCodeEnd":319,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/linkedql/registry.go#L284-L319","documentation":"parseLiteral converts a decoded JSON value into a quad.Value. It accepts plain scalars (string, number, bool) and JSON-LD value objects (maps with @value, optionally @language or @type). When the input matches none of these shapes it cannot be represented as a literal and this error is returned.","triggerScenarios":"parseValue falling through to parseLiteral with arrays, nested maps without @value, or nil — e.g. passing a JSON array as a step's object value, or a value object missing the required \"@value\" key.","commonSituations":"Authoring step documents with list-valued properties (RDF has no native list literal); value objects that use \"@values\" or misspell \"@value\"; nested node references where a literal was expected; null values in data sources.","solutions":["Pass a plain scalar (string, number, boolean) instead of an array or bare map.","For typed/lang values, use the exact JSON-LD shape: {\"@value\": \"...\", \"@type\": \"...\"} or {\"@value\": \"...\", \"@language\": \"en\"}.","If the value is a node reference, give it an \"@id\" so it parses as an identifier instead of reaching parseLiteral.","For lists, expand them into multiple triples/steps rather than a single array literal."],"exampleFix":"// before\n{\"@type\": \"http://www.w3.org/2001/XMLSchema#integer\"} // missing @value\n// after\n{\"@value\": \"42\", \"@type\": \"http://www.w3.org/2001/XMLSchema#integer\"}","handlingStrategy":"validation","validationCode":"func isLiteralShape(v interface{}) bool {\n  switch v.(type) {\n  case string, float64, bool, int, int64:\n    return true\n  case map[string]interface{}:\n    _, ok := v.(map[string]interface{})[\"@value\"]\n    return ok\n  }\n  return false\n}","typeGuard":"func asValueObject(v interface{}) (map[string]interface{}, bool) {\n  m, ok := v.(map[string]interface{})\n  if !ok { return nil, false }\n  _, has := m[\"@value\"]\n  return m, has\n}","tryCatchPattern":"val, err := parseLiteral(v)\nif err != nil && strings.Contains(err.Error(), \"can not parse\") {\n  return fmt.Errorf(\"literal fields accept scalars or {@value,...} objects, got %T\", v)\n}","preventionTips":["Never pass arrays or null where a single literal is expected — expand lists into multiple triples.","Spell JSON-LD keywords exactly: \"@value\", \"@type\", \"@language\".","Pre-validate step documents against the JSON-LD data model before registry calls."],"tags":["go","json-ld","literal","parsing"],"backgroundTag":"invalid-argument-value","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}