// JvFromJSONBytes takes a utf-8 byte sequence containing JSON and returns the // jv representation of it. func JvFromJSONBytes(b []byte) (*Jv, error) { jv := C.jv_parse((*C.char)(unsafe.Pointer(&b[0]))) if C.jv_is_valid(jv) == 0 { return nil, _ConvertError(jv) } return &Jv{jv}, nil }
// JvFromJSONString takes a JSON string and returns the jv representation of // it. func JvFromJSONString(str string) (*Jv, error) { cs := C.CString(str) defer C.free(unsafe.Pointer(cs)) jv := C.jv_parse(cs) if C.jv_is_valid(jv) == 0 { return nil, _ConvertError(jv) } return &Jv{jv}, nil }
func (j *jqExecutor) execute(input ...string) []string { jsons := strings.Join(input, "") parser := C.jv_parser_new(0) defer C.jv_parser_free(parser) // Make a simple input then convert to CString. cjsons := C.CString(jsons) defer C.free(unsafe.Pointer(cjsons)) C.jv_parser_set_buf(parser, cjsons, C.int(len(jsons)), 0) var response []string // Check if v is valid. for v := C.jv_parser_next(parser); C.jv_is_valid(v) == 1; v = C.jv_parser_next(parser) { C.jq_start(j.state, v, 0) // Check if res is valid. for res := C.jq_next(j.state); C.jv_is_valid(res) == 1; res = C.jq_next(j.state) { response = append(response, toString(res)) } } return response }
func isValid(jv C.jv) bool { return C.jv_is_valid(jv) != 0 }
// IsValid returns true if this Jv represents a valid JSON type, or false if it // is unitiaizlied or if it represents an error type // // Does not consume the invocant. func (jv *Jv) IsValid() bool { return C.jv_is_valid(jv.jv) != 0 }