![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
github.com/antonholmquist/jason
Jason is an easy-to-use JSON library for Go.
Jason is designed to be convenient for reading arbitrary JSON while still honoring the strictness of the language. Inspired by other libraries and improved to work well for common use cases. It currently focuses on reading JSON data rather than creating it. API Documentation can be found on godoc.org.
go get github.com/antonholmquist/jason
import (
"github.com/antonholmquist/jason"
)
The following golang values are used to represent JSON data types. It is consistent with how encoding/json
uses primitive types.
bool
, for JSON booleansjson.Number/float64/int64
, for JSON numbersstring
, for JSON strings[]*Value
, for JSON arraysmap[string]*Value
, for JSON objectsnil
for JSON nullCreate object from bytes. Returns an error if the bytes are not valid JSON.
v, err := jason.NewObjectFromBytes(b)
If the root object is not an array, use this method instead. It can then be cased to the expected type with one of the As-Methods.
v, err := jason.NewValueFromBytes(b)
Create value from a io.reader. Returns an error if the string couldn't be parsed.
v, err := jason.NewObjectFromReader(res.Body)
Reading values is easy. If the key path is invalid or type doesn't match, it will return an error and the default value.
name, err := v.GetString("name")
age, err := v.GetInt64("age")
verified, err := v.GetBoolean("verified")
education, err := v.GetObject("education")
friends, err := v.GetObjectArray("friends")
interests, err := v.GetStringArray("interests")
Reading nested values is easy. If the path is invalid or type doesn't match, it will return the default value and an error.
name, err := v.GetString("person", "name")
age, err := v.GetInt64("person", "age")
verified, err := v.GetBoolean("person", "verified")
education, err := v.GetObject("person", "education")
friends, err := v.GetObjectArray("person", "friends")
Looping through an array is done with GetValueArray()
or GetObjectArray()
. It returns an error if the value at that keypath is null (or something else than an array).
friends, err := person.GetObjectArray("friends")
for _, friend := range friends {
name, err := friend.GetString("name")
age, err := friend.GetNumber("age")
}
Looping through an object is easy. GetObject()
returns an error if the value at that keypath is null (or something else than an object).
person, err := person.GetObject("person")
for key, value := range person.Map() {
...
}
Example project:
package main
import (
"github.com/antonholmquist/jason"
"log"
)
func main() {
exampleJSON := `{
"name": "Walter White",
"age": 51,
"children": [
"junior",
"holly"
],
"other": {
"occupation": "chemist",
"years": 23
}
}`
v, _ := jason.NewObjectFromBytes([]byte(exampleJSON))
name, _ := v.GetString("name")
age, _ := v.GetNumber("age")
occupation, _ := v.GetString("other", "occupation")
years, _ := v.GetNumber("other", "years")
log.Println("age:", age)
log.Println("name:", name)
log.Println("occupation:", occupation)
log.Println("years:", years)
children, _ := v.GetStringArray("children")
for i, child := range children {
log.Printf("child %d: %s", i, child)
}
others, _ := v.GetObject("other")
for _, value := range others.Map() {
s, sErr := value.String()
n, nErr := value.Number()
if sErr == nil {
log.Println("string value: ", s)
} else if nErr == nil {
log.Println("number value: ", n)
}
}
}
Documentation can be found a godoc:
https://godoc.org/github.com/antonholmquist/jason
To run the project tests:
go test
Go 1.1 and up.
I remebered it from an email one of our projects managers sent a couple of years ago.
"Don't worry. We can handle both XML and Jason"
Anton Holmquist, http://twitter.com/antonholmquist
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.