MCPcopy Create free account
hub / github.com/compozy/agh / ValidateJSONObject

Function ValidateJSONObject

internal/tools/id.go:176–198  ·  view source on GitHub ↗

ValidateJSONObject validates a JSON Schema object payload.

(field string, raw json.RawMessage, required bool)

Source from the content-addressed store, hash-verified

174
175// ValidateJSONObject validates a JSON Schema object payload.
176func ValidateJSONObject(field string, raw json.RawMessage, required bool) error {
177 if len(raw) == 0 {
178 if required {
179 return NewValidationError(field, ReasonSchemaInvalid, "schema object is required")
180 }
181 return nil
182 }
183
184 var decoded map[string]json.RawMessage
185 if err := json.Unmarshal(raw, &decoded); err != nil {
186 return NewValidationError(field, ReasonSchemaInvalid, err.Error())
187 }
188 if decoded == nil {
189 if required {
190 return NewValidationError(field, ReasonSchemaInvalid, "schema must be a JSON object")
191 }
192 return nil
193 }
194 if err := validateJSONSchemaDocument("$", decoded); err != nil {
195 return NewValidationError(field, ReasonSchemaInvalid, err.Error())
196 }
197 return nil
198}

Callers 3

SchemaDigestFunction · 0.85
ValidateMethod · 0.85

Calls 3

NewValidationErrorFunction · 0.85
ErrorMethod · 0.45

Tested by 1