MCPcopy Create free account
hub / github.com/NoFxAiOS/nofx / validateJSONFormat

Function validateJSONFormat

kernel/engine_analysis.go:402–427  ·  view source on GitHub ↗
(jsonStr string)

Source from the content-addressed store, hash-verified

400}
401
402func validateJSONFormat(jsonStr string) error {
403 trimmed := strings.TrimSpace(jsonStr)
404
405 if !reArrayHead.MatchString(trimmed) {
406 if strings.HasPrefix(trimmed, "[") && !strings.Contains(trimmed[:min(20, len(trimmed))], "{") {
407 return fmt.Errorf("not a valid decision array (must contain objects {}), actual content: %s", trimmed[:min(50, len(trimmed))])
408 }
409 return fmt.Errorf("JSON must start with [{ (whitespace allowed), actual: %s", trimmed[:min(20, len(trimmed))])
410 }
411
412 if strings.Contains(jsonStr, "~") {
413 return fmt.Errorf("JSON cannot contain range symbol ~, all numbers must be precise single values")
414 }
415
416 for i := 0; i < len(jsonStr)-4; i++ {
417 if jsonStr[i] >= '0' && jsonStr[i] <= '9' &&
418 jsonStr[i+1] == ',' &&
419 jsonStr[i+2] >= '0' && jsonStr[i+2] <= '9' &&
420 jsonStr[i+3] >= '0' && jsonStr[i+3] <= '9' &&
421 jsonStr[i+4] >= '0' && jsonStr[i+4] <= '9' {
422 return fmt.Errorf("JSON numbers cannot contain thousand separator comma, found: %s", jsonStr[i:min(i+10, len(jsonStr))])
423 }
424 }
425
426 return nil
427}
428
429func min(a, b int) int {
430 if a < b {

Callers 1

extractDecisionsFunction · 0.85

Calls 2

minFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected