Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error interface {
Filename() string
Position() uint
Message() string
ErrCode() int
IncorrectUserType() string
}
func LengthOfJson ¶
LengthOfJson computes length of JSON document specified in this file. Deprecated: Use Len method of jschema.Schema instead.
Example ¶
// non-space characters after the top level value are allowed
b := []byte(`{ "key": 123 } some extra text`)
length, err := LengthOfJson(fs.NewFile("json", b))
if err != nil {
fmt.Println("Filename:", err.Filename()) // return "json"
fmt.Println("Position:", err.Position())
fmt.Println("Message:", err.Message())
return
}
fmt.Println(length)
Output: 14
func LengthOfSchema ¶
LengthOfSchema computes length of schema specified in th file. Deprecated: Use Len method of jschema.Schema instead.
Example ¶
// non-space characters after the top level value are allowed
b := []byte(`
{
"key": 123 // {min: 1}
}
some extra text
`)
length, err := LengthOfSchema(fs.NewFile("schema", b))
if err != nil {
fmt.Println("Filename:", err.Filename()) // return "schema"
fmt.Println("Position:", err.Position())
fmt.Println("Message:", err.Message())
return
}
fmt.Println(length)
Output: 29
func ValidateJson ¶
func ValidateJson( schemaFile *fs.File, extraTypes map[string]*fs.File, jsonFile *fs.File, areKeysOptionalByDefault bool, ) Error
ValidateJson the key of extraTypes parameter is the name of the type. The file name is used only for display in case of an error. They may not be the same. Deprecated: Use Validate method of jschema.Schema instead.
Example ¶
schem := []byte(` {
"aaa": 111 // {type: "@int"}
} `)
json := []byte(` {"aaa":333} `)
schemaFile := fs.NewFile("schema", schem)
jsonFile := fs.NewFile("json", json)
// The key of extraTypes parameter is the name of the type.
// The file name is used only for display in case of an error.
// They may not be the same.
extraTypes := make(map[string]*fs.File)
extraTypes["@int"] = fs.NewFile("@int", []byte(`222 // {min: 0}`))
err := ValidateJson(schemaFile, extraTypes, jsonFile, false)
if err != nil {
fmt.Println("Filename:", err.Filename())
fmt.Println("Position:", err.Position())
fmt.Println("Message:", err.Message())
return
}
fmt.Println("wonderful json")
Output: wonderful json
Click to show internal directories.
Click to hide internal directories.