1 package jsonschema 2 3 // JSONPather makes validators traversible by JSON-pointers, 4 // which is required to support references in JSON schemas. 5 type JSONPather interface { 6 // JSONProp take a string references for a given JSON property 7 // implementations must return any matching property of that name 8 // or nil if no such subproperty exists. 9 // Note this also applies to array values, which are expected to interpret 10 // valid numbers as an array index 11 JSONProp(name string) interface{} 12 } 13 14 // JSONContainer is an interface that enables tree traversal by listing 15 // the immideate children of an object 16 type JSONContainer interface { 17 // JSONChildren should return all immidiate children of this element 18 JSONChildren() map[string]JSONPather 19 } 20 21 func walkJSON(elem JSONPather, fn func(elem JSONPather) error) error { 22 if err := fn(elem); err != nil { 23 return err 24 } 25 26 if con, ok := elem.(JSONContainer); ok { 27 for _, ch := range con.JSONChildren() { 28 if err := walkJSON(ch, fn); err != nil { 29 return err 30 } 31 } 32 } 33 34 return nil 35 } 36