{"record":{"id":"8c94a0e0f3a450cd","repo":"cayleygraph/cayley","slug":"unknown-json-type-t","errorCode":null,"errorMessage":"Unknown JSON type: %T","messagePattern":"Unknown JSON type: %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/mql/build_iterator.go","lineNumber":93,"sourceCode":"\tcase []interface{}:\n\t\t// for JSON arrays\n\t\tq.isRepeated[path] = true\n\t\tif len(t) == 0 {\n\t\t\ts = buildAllResult(path)\n\t\t\toptional = true\n\t\t} else if len(t) == 1 {\n\t\t\ts, optional, err = q.buildShape(t[0], path)\n\t\t} else {\n\t\t\terr = fmt.Errorf(\"multiple fields at location root %s\", path.DisplayString())\n\t\t}\n\tcase map[string]interface{}:\n\t\t// for JSON objects\n\t\ts, err = q.buildShapeMap(t, path)\n\tcase nil:\n\t\ts = buildAllResult(path)\n\t\toptional = true\n\tdefault:\n\t\terr = fmt.Errorf(\"Unknown JSON type: %T\", query)\n\t}\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\ts = shape.Save{\n\t\tFrom: s,\n\t\tTags: []string{string(path)},\n\t}\n\treturn s, optional, nil\n}\n\nfunc (q *Query) buildShapeMap(query map[string]interface{}, path Path) (shape.Shape, error) {\n\tit := shape.IntersectOpt{\n\t\tSub: shape.Intersect{\n\t\t\tshape.AllNodes{},\n\t\t},\n\t}\n\toutputStructure := make(map[string]interface{})","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/mql/build_iterator.go#L75-L111","documentation":"buildShape in mql/build_iterator.go:93 switches over the Go type of each value in the MQL query JSON. Recognized types are []interface{}, map[string]interface{}, and nil; any other JSON scalar type (string, float64, bool) hits the default branch and produces this error. MQL query values must be objects, arrays, or null — not raw scalars.","triggerScenarios":"Running a MQL query containing a scalar value where a field spec is expected, e.g. {\"name\": \"bob\"} instead of {\"name\": nil} or {\"name\": [...]}.","commonSituations":"Authors coming from MongoDB-style MQL expecting scalar equality matching; the Cayley MQL dialect only accepts null (wildcard) or arrays/maps as values.","solutions":["Replace scalar values with nil (match anything) or a nested query array/map.","Restructure the query so scalar constraints are expressed as sub-fields or separate filtering.","Check the %T in the message to identify the unexpected scalar type.","Sanitize/validate query JSON before calling BuildIteratorTree."],"exampleFix":"// before\nquery := map[string]interface{}{\"name\": \"bob\"}\n// after\nquery := map[string]interface{}{\"name\": nil} // or nested spec","handlingStrategy":"validation","validationCode":"func validateMQLValueTypes(q map[string]interface{}) error {\n  for k, v := range q {\n    switch v.(type) {\n    case nil, []interface{}, map[string]interface{}:\n    default:\n      return fmt.Errorf(\"field %q: MQL values must be null, array, or object, got %T\", k, v)\n    }\n  }\n  return nil\n}","typeGuard":"func isMQLValue(v interface{}) bool {\n  switch v.(type) {\n  case nil, []interface{}, map[string]interface{}:\n    return true\n  }\n  return false\n}","tryCatchPattern":"it, err := mql.BuildIteratorTree(query)\nif err != nil {\n  if strings.Contains(err.Error(), \"Unknown JSON type\") {\n    return fmt.Errorf(\"replace scalar field values with nil or nested specs\")\n  }\n  return err\n}","preventionTips":["Use nil for wildcard field values, never scalars","Do not assume MongoDB-style scalar equality works in Cayley MQL","Validate the query document recursively before BuildIteratorTree"],"tags":["mql","query","go","json"],"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"}