Compare commits

...

3 Commits

Author SHA1 Message Date
Michel Couillard e3395843c8
Merge b877ac2b1c into c2bc5a409a 2024-06-04 20:50:30 +09:00
tidwall c2bc5a409a dark mode logo 2024-06-02 18:12:06 -07:00
Michel Couillard b877ac2b1c README: Array index as key for ForEach 2023-11-22 09:36:05 -05:00
4 changed files with 8 additions and 5 deletions

BIN
.github/images/logo-dark.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
.github/images/logo-light.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,7 +1,9 @@
<p align="center"> <p align="center">
<img <picture>
src="logo.png" <source media="(prefers-color-scheme: dark)" srcset="/.github/images/logo-dark.png">
width="240" height="78" border="0" alt="GJSON"> <source media="(prefers-color-scheme: light)" srcset="/.github/images/logo-light.png">
<img src="/.github/images/logo-light.png" width="240" alt="GJSON" >
</picture>
<br> <br>
<a href="https://godoc.org/github.com/tidwall/gjson"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a> <a href="https://godoc.org/github.com/tidwall/gjson"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a>
<a href="https://tidwall.com/gjson-play"><img src="https://img.shields.io/badge/%F0%9F%8F%90-playground-9900cc.svg?style=flat-square" alt="GJSON Playground"></a> <a href="https://tidwall.com/gjson-play"><img src="https://img.shields.io/badge/%F0%9F%8F%90-playground-9900cc.svg?style=flat-square" alt="GJSON Playground"></a>
@ -338,13 +340,14 @@ println(name.String()) // prints "Elliotte"
The `ForEach` function allows for quickly iterating through an object or array. The `ForEach` function allows for quickly iterating through an object or array.
The key and value are passed to the iterator function for objects. The key and value are passed to the iterator function for objects.
Only the value is passed for arrays. With an array the key is an index and the value is passed.
Returning `false` from an iterator will stop iteration. Returning `false` from an iterator will stop iteration.
```go ```go
result := gjson.Get(json, "programmers") result := gjson.Get(json, "programmers")
result.ForEach(func(key, value gjson.Result) bool { result.ForEach(func(key, value gjson.Result) bool {
println(value.String()) println(key.Int()) // index of the array
println(value.String())
return true // keep iterating return true // keep iterating
}) })
``` ```

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB