dgraph-io/dgraph · error
only array of map allowed at root
Error message
only array of map allowed at root
What it means
FastParseJSON (chunker/json_parser.go:731) expects the parsed JSON root to be an array of objects; each array element must be a map[string]interface{} representing a node. If any element is not a map, the fast parser stops with this error. It exists because the streaming fast path cannot process non-object root entries.
Source
Thrown at chunker/json_parser.go:731
}
buf.checkForDeletion(mr, m, op)
} else if typ == simdjson.TypeArray {
// the root element is an array, so parse the array
if arr, err = tmp.Array(arr); err != nil {
return err
}
// attempt to convert to []interface{}
a, err := arr.Interface()
if err != nil {
return err
}
if len(a) > 0 {
// attempt to convert each array element to a
// map[string]interface{} for further parsing
var o interface{}
for _, o = range a {
if _, ok := o.(map[string]interface{}); !ok {
return errors.New("only array of map allowed at root")
}
// pass to next parsing stage
mr, err := buf.mapToNquads(o.(map[string]interface{}), op, "")
if err != nil {
return err
}
buf.checkForDeletion(mr, o.(map[string]interface{}), op)
}
}
}
default:
return errors.New("initial element not found in json")
}
return nil
}
// ParseJSON parses the given byte slice and pushes the parsed NQuads into the buffer.
func (buf *NQuadBuffer) ParseJSON(b []byte, op int) error {View on GitHub (pinned to 759e242be6)
Solutions
- Make the root a JSON array of objects: [{...},{...}].
- Wrap bare scalar values into objects with a predicate key before parsing.
- Use ParseJSON instead if your input format legitimately differs, or preprocess/convert the document.
Example fix
// before
["alice", "bob"]
// after
[{"name": "alice"}, {"name": "bob"}] Defensive patterns
Strategy: validation
Validate before calling
func rootIsArrayOfMaps(b []byte) error {
var a []interface{}
if err := json.Unmarshal(b, &a); err != nil {
return err
}
for i, e := range a {
if _, ok := e.(map[string]interface{}); !ok {
return fmt.Errorf("element %d is not an object", i)
}
}
return nil
} Type guard
func isArrayOfMaps(v interface{}) bool {
a, ok := v.([]interface{})
if !ok {
return false
}
for _, e := range a {
if _, ok := e.(map[string]interface{}); !ok {
return false
}
}
return len(a) > 0
} Try / catch
if err := buf.FastParseJSON(b, op); err != nil && strings.Contains(err.Error(), "only array of map allowed at root") {
// wrap scalar entries in objects and retry
} Prevention
- Always emit a root array of objects for bulk JSON imports
- Validate the root shape with json.Unmarshal into []map[string]interface{} first
- Convert scalar-only exports before feeding the fast parser
When it happens
Trigger: Calling FastParseJSON on a JSON array whose root contains non-object elements, e.g. [1,2,3] or ["a","b"], or a scalar root like 42.
Common situations: Export files from other tools that emit arrays of scalars, or JSONL lines that are bare values rather than objects; users hitting the fast bulk-load path with malformed exports.
Related errors
- initial element not found in json
- unexpected type for val for attr: %s while converting to nqu
- error while trying to parse value: %+v as geo val
- couldn't convert value: %s to geo type
- got unsupported type for list: %s
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/f59ca487497d8b5b.
Report an issue: GitHub.