antonholmquist / jason Goto Github PK
View Code? Open in Web Editor NEWEasy-to-use JSON Library for Go
Home Page: http://godoc.org/github.com/antonholmquist/jason
License: MIT License
Easy-to-use JSON Library for Go
Home Page: http://godoc.org/github.com/antonholmquist/jason
License: MIT License
It would be nice to have an API that also allowed mutation. Any interest?
Would you accept a pull request with such functionality?
json.NewValueFromString / NewValueFromReader are used around the README but don't appear to exist.
Is there an API to convert an Object to a JSON string?
Hi,
I've a highly nested Json that I want to iterate through. Here is an example.
[{"a":[{"3":5},{"2":3},{"b":[{"n":2},{"b":"c"},{"c":[{"d":1},{"u":2}]}]}]},{"a":[{"3":5},{"2":3},{"b":[{"n":2},{"b":"c"},{"c":[{"d":1},{"f":[[2,3,4,{"tik":1}],3,5]}]}]}]},{"a":[{"3":5},{"2":3},{"b":[{"n":2},{"b":"c"},{"c":[{"d":1},{"i":2}]}]}]}]
Ho do I get to the tik
key?
Also probably an unrelated question, is there a way how to search this highly nested Json based on key or value?
Thank you
First: We use this library at work in almost every service and really love it! ๐
But we sometimes need to create Jason objects to call functions which expect them.
What do you think of a func to create objects via Go values? We're currently just marshalling via encoding/json
and importing to jason with NewObjectFromBytes
, but I'm sure there's a better and more performant way to achieve this.
If you're ok with this, I'm happy to create a PR.
My idea would be something like jason.NewObject(map[string]interface{}) *jason.Object
.
What do you think?
Keep up the good work ๐ช
This throws an error:
// components is an array of keys, first two elements being some internal values
var children []string
children=components[2:]
value,err:=v.GetString(children...)
However, this works:
value,err:=v.GetString(children[0],children[1],[children[2])
Am I doing something wrong?
Is there a way to find the type of a jason.Value
Or will it always just be for reading?
Value is used to the official JSON grammar to describe any of the data types: http://tools.ietf.org/html/rfc7158#section-3
While this library does present an interesting and totally valid alternative, it's not idiomatic at all. The most common approach (by far) is to just use the encoding/json
package. This includes parsing arbitrary data, as detailed in the JSON and Go blog post.
You're a lifesaver. The default package is easy to use with short snippets of json; but, this makes working with large json files a dream. Thank you so much.
If the amount of data to 50kb, performance testing will be very slow๏ผ
package main
import (
"fmt"
"github.com/antonholmquist/jason"
)
func main() {
data := []byte(`{
"hits":{
"total":2,
"max_score":4.631368,
"hits":[
{
"_source":{
"account_number":298,
"balance":34334,
"firstname":"Bullock",
"lastname":"Marsh"
}
},
{
"_source":{
"account_number":25,
"balance":40540,
"firstname":"Virginia",
"lastname":"Ayala"
}
}
]
}
}`)
js, _ := jason.NewObjectFromBytes(data)
//get total
total, _ := js.GetInt64("hits", "total")
fmt.Println(total)
//get _source list
hitsjson, _ := js.GetObjectArray("hits", "hits")
for _, v := range hitsjson {
fmt.Printf("%v\n", v.GetString("_source", "firstname"))
}
}
error:
multiple-value v.GetString() in single-value context
after doing so much json parsing with interface {} directly this is wonderful.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.