ddo / Pick Json
Licence: mit
pick stuff from json - FAST
Stars: ✭ 67
Programming Languages
go
31211 projects - #10 most used programming language
pick-json
pick stuff from json - FAST
Feature
- fast.
- simple.
- lightweight. just stdlib
"encoding/json"
and ~2.0 KB - incomplete json still work well.
- no need to define parent key for nested target.
Fast? How?
- read json as stream.
- stop when found.
- and you can also set the limit.
Use cases
- we just need a part of the json.
- in case you need to parse all the json, please use the
"encoding/json"
Unmarshal
orDecoder
Examples
JSON_EXAMPLE := `{
"benchmark": "benchmark text 1",
"menu": {
"header": "SVG Viewer",
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center",
"hidden": true
}
},
"benchmark": "benchmark text 2",
}`
- pick string
benchmarks := PickString(strings.NewReader(JSON_EXAMPLE), "benchmark", 0)
// [benchmark text 1 benchmark text 2]
- pick string just the 1st one
benchmarks := PickString(strings.NewReader(JSON_EXAMPLE), "benchmark", 1)
// [benchmark text 1]
- pick bool
hidden := PickBool(strings.NewReader(JSON_EXAMPLE), "hidden", 0)
// [true]
- pick object
type Image struct {
Src string `json:"src"`
Name string `json:"name"`
HOffset int `json:"hOffset"`
VOffset int `json:"vOffset"`
Alignment string `json:"alignment"`
}
var image Image
err := PickObject(strings.NewReader(JSON_EXAMPLE), "image", &image)
// {Images/Sun.png sun1 250 250 center}
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].