siyuan-note/siyuan · error
generated tree [ ] is not valid JSON
Error message
generated tree [%s] is not valid JSON
What it means
After rendering the staged tree to JSON via NewJSONRenderer, writeObsidianTempTree verifies the output with `json.Valid`. If the renderer produced invalid JSON, staging fails with this error naming the tree's HPath. It guards against writing a corrupt .sy document file.
Solutions
- Re-run the import for the failing document to see if it reproduces deterministically
- Inspect the note at tree.HPath for structures that break JSON rendering (rare inline spans) and simplify them
- Update the kernel/Lute and retry; if reproducible, report the document as a renderer bug
Example fix
// before: hard fail
data := renderer.Render()
if !json.Valid(data) {
return fmt.Errorf("generated tree [%s] is not valid JSON", tree.HPath)
}
// after: log and skip the bad document instead of aborting the whole import
data := renderer.Render()
if !json.Valid(data) {
stats.AddSkipped("invalid JSON for " + tree.HPath)
return nil
} Defensive patterns
Strategy: try-catch
Try / catch
if err := writeObsidianTempTree(docsTemp, tree); err != nil {
if strings.Contains(err.Error(), "is not valid JSON") {
log.Printf("renderer bug for %s, skipping", tree.HPath)
return nil
}
return err
} Prevention
- Keep Lute and renderer versions aligned
- Test imports on documents with unusual inline spans
- Report reproducible invalid-JSON documents upstream
When it happens
Trigger: Calling `writeObsidianTempTree` when `renderer.Render()` returns bytes that fail `json.Valid(data)`.
Common situations: A Lute/renderer bug emitting malformed JSON for unusual inline structures; corrupted tree content after normalization; version mismatch between renderer and JSON schema expectations.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/e5d030c7a6223123.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/import_obsidian.go:2372
tree.Root.SetIALAttr("title", doc.Title)
tree.Root.SetIALAttr("updated", util.TimeFromID(doc.ID))
tree.Root.RemoveIALAttrsByPrefix("custom-")
}
func writeObsidianTempTree(docsTemp string, tree *parse.Tree) error {
if tree == nil || tree.Root == nil {
return errors.New("cannot stage an empty tree")
}
if tree.Root.FirstChild == nil {
tree.Root.AppendChild(treenode.NewParagraph(""))
}
treenode.UpgradeSpec(tree)
tree.Root.SetIALAttr("type", "doc")
luteEngine := util.NewLute()
renderer := render.NewJSONRenderer(tree, luteEngine.RenderOptions, luteEngine.ParseOptions)
data := renderer.Render()
if !json.Valid(data) {
return fmt.Errorf("generated tree [%s] is not valid JSON", tree.HPath)
}
if !util.UseSingleLineSave {
var buffer bytes.Buffer
if err := json.Indent(&buffer, data, "", "\t"); err != nil {
return err
}
data = buffer.Bytes()
}
target := filepath.Join(docsTemp, filepath.FromSlash(strings.TrimPrefix(tree.Path, "/")))
if err := os.MkdirAll(filepath.Dir(target), 0755); err != nil {
return err
}
return filelock.WriteFile(target, data)
}
func copyStableObsidianFile(source *obsidianSourceFile, destination string) error {
if err := validateObsidianSourceMetadata(source); err != nil {
return errView on GitHub (pinned to 9f775e8a12)