Documentation
¶
Overview ¶
Package jsonc is a minimal JSON-with-Comments (JSONC) parser.
It accepts the same input as encoding/json.Unmarshal, plus:
- // line comments to end of line
- /* block comments */
- trailing commas in objects and arrays
Output is identical to standard JSON parse for the same input without comments. Comment text is discarded; the result is a normal Go interface{} (or other target type) populated as if the comments were never there.
GrayCode native implementation. bin/lib/settings.js (parseJSONC). Ported to native Go.
validate.go: pre-write validation for Claude Code settings fields.
Settings.json hook-field validation. performs a Zod-style pre-check on Claude Code settings.json before writing. This file ports that check to native Go, using the encoding/json conventions of the existing internal/config package.
Validation is permissive by design: unknown fields are allowed (forward compat), but known fields are type-checked and value validated. The intent is to catch typos and accidental schema changes before they corrupt a user's settings.
Index ¶
- Variables
- func IsValidation(err error) bool
- func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)
- func PrettyError(err error) string
- func Strip(src []byte) ([]byte, error)
- func Unmarshal(data []byte, v interface{}) error
- func Valid(data []byte) bool
- type ErrValidation
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidJSON = errors.New("jsonc: invalid input")
ErrInvalidJSON is returned when the input cannot be parsed even after comment/trailing-comma stripping.
Functions ¶
func IsValidation ¶
IsValidation reports whether err is an ErrValidation.
func MarshalIndent ¶
MarshalIndent is a thin wrapper over json.MarshalIndent kept here for API symmetry. The output is plain JSON (no comments).
func PrettyError ¶
PrettyError returns a human-friendly error message for a JSONC parse failure. It is intended for display in CLI output.
func Strip ¶
Strip removes JSONC comments and trailing commas from src and returns a byte slice suitable for encoding/json.Unmarshal.
Types ¶
type ErrValidation ¶
ErrValidation is the base class for all field validation errors.
func (*ErrValidation) Error ¶
func (e *ErrValidation) Error() string
type ValidationResult ¶
type ValidationResult struct {
Errors []error
}
ValidationResult is the outcome of validating a Claude Code settings document. Errors are non-empty only if validation failed.
func ValidateClaudeSettings ¶
func ValidateClaudeSettings(doc map[string]interface{}) *ValidationResult
ValidateClaudeSettings validates a parsed Claude Code settings document (a map[string]interface{}). Returns a ValidationResult describing any issues. The function never returns a non-nil error; validation problems are reported through the result.
func (*ValidationResult) Add ¶
func (r *ValidationResult) Add(field, reason string)
Add appends a validation error to r.
func (*ValidationResult) AddErr ¶
func (r *ValidationResult) AddErr(err error)
AddErr appends a pre-built error to r.
func (*ValidationResult) Valid ¶
func (r *ValidationResult) Valid() bool
Valid reports whether r contains no validation errors.