plandex-ai/plandex · error

error parsing schema JSON: %v

Error message

error parsing schema JSON: %v

What it means

LoadJSON treats its source string as a literal JSON schema document (not a path) and decodes it with json.Decoder. This error means the provided source string is not valid JSON — e.g. an accidental non-JSON string was passed instead of a schema path or schema JSON.

Source

Thrown at app/cli/schema/schemas.go:128

		}
		data, err := l.fs.ReadFile(schemaPath)
		if err != nil {
			return nil, fmt.Errorf("error reading embedded schema %s: %v", schemaPath, err)
		}
		var v interface{}
		dec := json.NewDecoder(bytes.NewReader(data))
		dec.UseNumber() // use numbers instead of floats
		if err := dec.Decode(&v); err != nil {
			return nil, fmt.Errorf("error parsing embedded schema %s: %v", source, err)
		}
		return v, nil
	}

	var v interface{}
	dec := json.NewDecoder(bytes.NewReader([]byte(source)))
	dec.UseNumber() // use numbers instead of floats
	if err := dec.Decode(&v); err != nil {
		return nil, fmt.Errorf("error parsing schema JSON: %v", err)
	}
	return v, nil
}

func (l *embeddedSchemaLoader) JsonReference() (gojsonreference.JsonReference, error) {
	return gojsonreference.NewJsonReference(scheme + l.source)
}

type embeddedLoaderFactory struct{}

func (embeddedLoaderFactory) New(source string) gojsonschema.JSONLoader {
	source = strings.TrimPrefix(source, scheme)
	return newEmbeddedSchemaLoader(SchemaPath(source))
}

func (l *embeddedSchemaLoader) LoaderFactory() gojsonschema.JSONLoaderFactory {
	return embeddedLoaderFactory{}
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Confirm whether LoadJSON expects a path or raw JSON and pass the right one
  2. Validate the inline schema string with jq and fix syntax errors
  3. If you meant a file, use the embedded loader path so it is read as a file
  4. Remove JSON-incompatible syntax (comments, trailing commas)

Example fix

// before
loader.LoadJSON("model-pack-schema") // raw string, not JSON
// after
loader.LoadJSON(`{"type":"object","properties":{}}`)
Defensive patterns

Strategy: validation

Validate before calling

func isJSONString(s string) bool {
    var v interface{}
    return json.Unmarshal([]byte(s), &v) == nil
}
// check before calling LoadJSON with inline schema source

Try / catch

v, err := loader.LoadJSON(source)
if err != nil && strings.Contains(err.Error(), "error parsing schema JSON") {
    // source was meant to be a file path or is malformed JSON
    return fmt.Errorf("inline schema is not valid JSON: %w", err)
}

Prevention

When it happens

Trigger: Calling LoadJSON with a source string containing invalid JSON: passing a schema name/path instead of JSON content while the embedded-path branch was skipped, or a malformed inline schema.

Common situations: Confusing the loader API by passing a filename where raw JSON is expected; inline schema copy-pasted with comments or trailing commas.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/05d8dab664dfaa89. Report an issue: GitHub.