Skip to content

is here any function to check the data is an valid JSON-encoded data #185

Closed
@yumaojun03

Description

@yumaojun03

is the data isn't an validate JSON data, json-iterator return nil, like this

	val := []byte(`{"ID":1,"Name":Reds","Colors":["Crimson","Red","Ruby","Maroon"]}`)
	fmt.Printf(jsoniter.Get(val, "Colors", 0).ToString())

so, when i parse json data, first step check the data format, in my program i use Valid function in "encoding/json", like this

	val := []byte(`{"ID":1,"Name":Reds","Colors":["Crimson","Red","Ruby","Maroon"]}`)
	if ok := json.Valid(val); !ok {
		fmt.Println("not valid JSON-encoded data")
	} else {
		fmt.Printf(jsoniter.Get(val, "Colors", 0).ToString())
	}

so, can you provide an data check function like standard lib's Valid?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions