11# jsonquery
22
3- [ ![ Build Status] ( https://travis-ci.org/antchfx/jsonquery.svg?branch=master )] ( https://travis-ci.org/antchfx/jsonquery )
4- [ ![ Coverage Status] ( https://coveralls.io/repos/github/antchfx/jsonquery/badge.svg?branch=master )] ( https://coveralls.io/github/antchfx/jsonquery?branch=master )
3+ [ ![ Build Status] ( https://github.com/antchfx/jsonquery/actions/workflows/testing.yml/badge.svg )] ( https://github.com/antchfx/jsonquery/actions/workflows/testing.yml )
54[ ![ GoDoc] ( https://godoc.org/github.com/antchfx/jsonquery?status.svg )] ( https://godoc.org/github.com/antchfx/jsonquery )
65[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/antchfx/jsonquery )] ( https://goreportcard.com/report/github.com/antchfx/jsonquery )
76
@@ -25,7 +24,6 @@ go get github.com/antchfx/jsonquery
2524
2625The below code may be help your understand what it does. We don't need pre-defined structure or using regexp to extract some data in JSON file, gets any data is easy and fast in jsonquery now.
2726
28-
2927Using an xpath like syntax to access specific fields of a json structure.
3028
3129``` go
@@ -62,13 +60,14 @@ func main() {
6260 // or
6361 age = jsonquery.FindOne (doc, " person/age" )
6462 fmt.Printf (" %#v [%T ]\n " , age.Value (), age.Value ()) // prints 31[float64]
65-
66- hobbies := jsonquery.FindOne (doc, " //hobbies" )
63+
64+ hobbies := jsonquery.FindOne (doc, " //hobbies" )
6765 fmt.Printf (" %#v \n " , hobbies.Value ()) // prints []interface {}{"coding", "eating", "football"}
6866 firstHobby := jsonquery.FindOne (doc, " //hobbies/*[1]" )
6967 fmt.Printf (" %#v \n " , firstHobby.Value ()) // "coding"
7068}
7169```
70+
7271Iterating over a json structure.
7372
7473``` go
@@ -158,16 +157,18 @@ for _, n := range list {
158157 fmt.Print (n.Value ().(float64 ))
159158}
160159```
160+
161161// Output: ` 1,2,3,4,5,6 `
162162
163163#### Convert JSON object to XML file
164+
164165``` go
165166s := ` [{"name":"John", "age":31, "female":false, "city":null}]`
166167doc , _ := jsonquery.Parse (strings.NewReader (s))
167168fmt.Println (doc.OutputXML ())
168169```
169170
170- ### Methods
171+ ### Methods
171172
172173#### FindOne()
173174
@@ -259,7 +260,6 @@ Convert current JSON object to XML format.
259260 },
260261 "expensive" : 10
261262}
262-
263263```
264264
265265``` go
@@ -317,20 +317,20 @@ Output the below XML:
317317
318318## XPath Tests
319319
320- | Query | Matched | Native Value Types | Native Values |
321- | ------- | -------------| -------- | -------------|
322- | ` //book ` | 1 | [ ] interface{} | ` {"book": [{"id":1,... }, {"id":2,... }, {"id":3,... }, {"id":4,... }]} ` |
323- | ` //book/* ` | 4 | [ map[ string] interface{}] | ` {"id":1,... } ` , ` {"id":2,... } ` , ` {"id":3,... } ` , ` {"id":4,... } ` |
324- | ` //*[price<12.99] ` | 2 | [ map[ string] interface{}] | ` {"id":1,...} ` , ` {"id":3,...} ` |
325- | ` //book/*/author ` | 4 | [ ] string | ` {"author": "Nigel Rees"} ` , ` {"author": "Evelyn Waugh"} ` , ` {"author": "Herman Melville"} ` , ` {"author": "J. R. R. Tolkien"} ` |
326- | ` //book/*[last()] ` | 1 | map[ string] interface {} | ` {"id":4,...} ` |
327- | ` //book/*[2] ` | 1 | map[ string] interface{} | ` {"id":2,...} ` |
328- | ` //*[isbn] ` | 2 | [ map[ string] interface{}] | ` {"id":3,"isbn":"0-553-21311-3",...} ` ,` {"id":4,"isbn":"0-395-19395-8",...} ` |
329- | ` //*[isbn='0-553-21311-3'] ` | 1 | map[ string] interface{} | ` {"id":3,"isbn":"0-553-21311-3",...} ` |
330- | ` //bicycle ` | 1 | map[ string] interface {} | ` {"bicycle":{"color":...,}} ` |
331- | ` //bicycle/color[text()='red'] ` | 1 | map[ string] interface {} | ` {"color":"red"} ` |
332- | ` //*/category[contains(.,'refer')] ` | 1 | string | ` {"category": "reference"} ` |
333- | ` //price[.=22.99] ` | 1 | float64 | ` {"price": 22.99} ` |
334- | ` //expensive/text() ` | 1 | string | ` 10 ` |
335-
336- For more supports XPath feature and function see https://github.com/antchfx/xpath
320+ | Query | Matched | Native Value Types | Native Values |
321+ | ----------------------------------- | ------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------- |
322+ | ` //book ` | 1 | [ ] interface{} | ` {"book": [{"id":1,... }, {"id":2,... }, {"id":3,... }, {"id":4,... }]} ` |
323+ | ` //book/* ` | 4 | [ map[ string] interface{}] | ` {"id":1,... } ` , ` {"id":2,... } ` , ` {"id":3,... } ` , ` {"id":4,... } ` |
324+ | ` //*[price<12.99] ` | 2 | [ map[ string] interface{}] | ` {"id":1,...} ` , ` {"id":3,...} ` |
325+ | ` //book/*/author ` | 4 | [ ] string | ` {"author": "Nigel Rees"} ` , ` {"author": "Evelyn Waugh"} ` , ` {"author": "Herman Melville"} ` , ` {"author": "J. R. R. Tolkien"} ` |
326+ | ` //book/*[last()] ` | 1 | map[ string] interface {} | ` {"id":4,...} ` |
327+ | ` //book/*[2] ` | 1 | map[ string] interface{} | ` {"id":2,...} ` |
328+ | ` //*[isbn] ` | 2 | [ map[ string] interface{}] | ` {"id":3,"isbn":"0-553-21311-3",...} ` ,` {"id":4,"isbn":"0-395-19395-8",...} ` |
329+ | ` //*[isbn='0-553-21311-3'] ` | 1 | map[ string] interface{} | ` {"id":3,"isbn":"0-553-21311-3",...} ` |
330+ | ` //bicycle ` | 1 | map[ string] interface {} | ` {"bicycle":{"color":...,}} ` |
331+ | ` //bicycle/color[text()='red'] ` | 1 | map[ string] interface {} | ` {"color":"red"} ` |
332+ | ` //*/category[contains(.,'refer')] ` | 1 | string | ` {"category": "reference"} ` |
333+ | ` //price[.=22.99] ` | 1 | float64 | ` {"price": 22.99} ` |
334+ | ` //expensive/text() ` | 1 | string | ` 10 ` |
335+
336+ For more supports XPath feature and function see https://github.com/antchfx/xpath
0 commit comments