Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Jul 19, 2015
1 parent 001079a commit 4579b00
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ value, ok = jsonParsed.Path("does.not.exist").Data().(float64)
...
```

###Iterating objects

```go
...

jsonParsed, _ := gabs.ParseJSON([]byte(`{"object":{ "first": 1, "second": 2, "third": 3 }}`))

// S is shorthand for Search
children, _ := jsonParsed.S("object").ChildrenMap()
for key, child := range children {
fmt.Printf("key: %v, value: %v\n", key, child.Data().(string))
}

...
```

###Iterating arrays

```go
Expand Down Expand Up @@ -165,6 +181,37 @@ Will print:
{"foo":{"array":[10,20,30]}}
```

Working with arrays by index:

```go
...

jsonObj := gabs.New()

// Create an array with the length of 3
jsonObj.ArrayOfSize(3, "foo")

jsonObj.S("foo").SetIndex("test1", 0)
jsonObj.S("foo").SetIndex("test2", 1)

// Create an embedded array with the length of 3
jsonObj.S("foo").ArrayOfSizeI(3, 2)

jsonObj.S("foo").Index(2).SetIndex(1, 0)
jsonObj.S("foo").Index(2).SetIndex(2, 1)
jsonObj.S("foo").Index(2).SetIndex(3, 2)

fmt.Println(jsonObj.String())

...
```

Will print:

```
{"foo":["test1","test2",[1,2,3]]}
```

###Converting back to JSON

This is the easiest part:
Expand Down

0 comments on commit 4579b00

Please sign in to comment.