Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
antonholmquist committed Dec 2, 2014
1 parent adba63a commit c0a8c57
Showing 1 changed file with 88 additions and 1 deletion.
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Jason intends to be an idiomatic JSON library for Go.

```
go get github.com/antonholmquist/jason`
```


## Import

```
Expand All @@ -19,6 +19,86 @@ import (
)
```

## Examples

### Create from string

```
root, err := jason.NewFromString(exampleJSON)
```

### Create from net/http response
```
root, err := jason.NewFromReader(res.Body)
```

### Read values

Reading values is easy. If the key is invalid, it will return the default value.

```
root.Get("name").String()
root.Get("age").Number()
root.Get("verified").Bool()
root.Get("education").Object()
root.Get("friends").Array()
```

### Read nested values

Reading nested values is easy. If the path is invalid, it will return the default value, for instance the empty string.

```
root.Get("person", "name").String()
root.Get("person", "age").Number()
root.Get("person", "verified").Bool()
root.Get("person", "education").Object()
root.Get("person", "friends").Array()
```

### Check if values exists

To check if a value exist, use `Exists()`.

```
root.Get("person", "name").Exists()
```


### Validate values

To check if a value at the keypath really is what you think it is, use the `Is()-methods`.

```
root.Get("name").IsString()
root.Get("age").IsNumber()
root.Get(""verified").IsBool()
root.Get("education").IsObject()
root.Get("friends").IsArray()
```

### Loop through array

Looping through an array is easy and will never return an exeption. `Array()` returns an empty array if the value at that keypath is null or something else than an array.

```
for _, friend := person.Get("friends").Array() {
name := friend.Get("name").String()
age := friend.Get("age").Number()
}
```


## Documentation

https://godoc.org/github.com/antonholmquist/jason


## Sample Project

```
Expand All @@ -33,6 +113,7 @@ func main() {
exampleJSON := `{
"name": "Walter White",
"age": 51,
"children": [
"junior",
Expand All @@ -59,4 +140,10 @@ func main() {
}
```

## Test

```
go test
```

0 comments on commit c0a8c57

Please sign in to comment.