json

package
v2.15.3-dev-ko-test2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateJSONSchemaString added in v2.10.0

func GenerateJSONSchemaString(value interface{}) ([]byte, error)

func MarshalIndent

func MarshalIndent(jsonContent []byte) []byte

MarshalIndent takes json encoded content as a []byte and tries to indent it with two spaces If it is not able to marshal the content it returns the []byte as is and prints a warning and returns the error

func ReflectJSONSchema added in v2.10.0

func ReflectJSONSchema(value interface{}) *jsonschema.Schema

func ValidateJson

func ValidateJson(data string, location Location) error

Types

type JsonValidationError

type JsonValidationError struct {

	// FileName is the file name (full qualified) where the error happened
	// This field is always filled.
	Location Location `json:"jsonErrorLocation"`
	// LineNumber contains the line number (starting by one) where the error happened
	// If we don't have the information, this is -1.
	LineNumber int `json:"lineNumber"`
	// CharacterNumberInLine contains the character number (starting by one) where
	// the error happened. If we don't have the information, this is -1.
	CharacterNumberInLine int `json:"characterNumberInLine"`
	// LineContent contains the full line content of where the error happened
	// If we don't have the information, this is an empty string.
	LineContent string `json:"lineContent"`
	// PreviousLineContent contains the full line content of the line before LineContent
	// If we don't have the information, this is an empty string.
	PreviousLineContent string `json:"previousLineContent"`
	// Err is the original error which happened during the json unmarshalling.
	Err error `json:"error"`
}

JsonValidationError is an error which contains more information about where the error appeared in the json file which was validated. It contains the fileName, line number, character number, and line content as additional information. Furthermore, it contains the original error (the cause) which happened during the json unmarshalling.

func (JsonValidationError) ContainsLineInformation

func (e JsonValidationError) ContainsLineInformation() bool

ContainsLineInformation indicates whether additional line information is present in the error.

func (JsonValidationError) Error

func (e JsonValidationError) Error() string

func (JsonValidationError) PrettyError

func (e JsonValidationError) PrettyError() string

type Location

type Location struct {
	Coordinate       coordinate.Coordinate `json:"coordinate"`
	Group            string                `json:"group"`
	Environment      string                `json:"environment"`
	TemplateFilePath string                `json:"templateFilePath"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL