Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EachKey ¶
Iterates though each key in json. Does nothing if json is not an object.
Memory usage: O(1), Time usage: O(n)
Example ¶
package main
import (
"fmt"
"github.com/sheerun/yson"
)
func main() {
json := []byte(`{
"foo": "bar",
"fiz": "fuz",
"1": "2"
}`)
yson.EachKey(json, func(key []byte) {
fmt.Printf("%s ", string(key))
})
}
Output: foo fiz 1
func EachPair ¶
Iterates though each key and value in json. Does nothing if json is not an object.
Use it for iterating over huge input, as it uses GC better than yson.EachStringKeyAndValue(json)
Memory usage: O(1), Time usage: O(n)
Example ¶
package main
import (
"fmt"
"github.com/sheerun/yson"
)
func main() {
json := []byte(`{
"foo": "bar",
"fiz": "fuz",
"1": "2"
}`)
yson.EachPair(json, func(key []byte, value []byte) {
fmt.Printf("%s:%s ", key, value)
})
}
Output: foo:bar fiz:fuz 1:2
func EachValue ¶
Iterates though each value in json. Does nothing if json is not an object.
Memory usage: O(1), Time usage: O(n)
Example ¶
package main
import (
"fmt"
"github.com/sheerun/yson"
)
func main() {
json := []byte(`{
"foo": "bar",
"fiz": "fuz",
"1": "2"
}`)
yson.EachValue(json, func(key []byte) {
fmt.Printf("%s ", string(key))
})
}
Output: bar fuz 2
func Get ¶
Gets single element from json.
Warning: the behavior for fetching items by numeric key is for now undefined.
Memory usage: O(1), Time usage: O(n)
Example ¶
package main
import (
"fmt"
"github.com/sheerun/yson"
)
func main() {
json := []byte(`{
"foo": "bar",
"fiz": "fuz"
}`)
fmt.Printf("%s", yson.Get(json, "foo"))
}
Output: bar
func Load ¶
Parses json to go-lang structure or value
Memory usage: O(1), Time usage: O(1)
Example ¶
package main
import (
"fmt"
"github.com/sheerun/yson"
)
func main() {
json := []byte(`{ "foo": 12 }`)
var i int = 0
err := yson.Load(yson.Get(json, "foo"), &i)
if err != nil {
panic(err)
}
fmt.Printf("%d", i+1)
}
Output: 13
Types ¶
This section is empty.