<commit_before># jsonq

Simplify your golang json usage by extracting fields or items from arrays and
objects with a simple, hierarchical query. [API
Documentation](http://go.pkgdoc.org/github.com/jmoiron/jsonq) on go.pkgdoc.org.

# installing

```
go get github.com/jmoiron/jsonq
```

# usage

Given some json data like:

```javascript
{
	"foo": 1,
	"bar": 2,
	"test": "Hello, world!",
	"baz": 123.1,
	"array": [
		{"foo": 1},
		{"bar": 2},
		{"baz": 3}
	],
	"subobj": {
		"foo": 1,
		"subarray": [1,2,3],
		"subsubobj": {
			"bar": 2,
			"baz": 3,
			"array": ["hello", "world"]
		}
	},
	"bool": true
}
```

Decode it into a `map[string]interrface{}`:

```go
import (
	"strings"
	"encoding/json"
	"github.com/jmoiron/jsonq"
)

data := map[string]interface{}{}
dec := json.NewDecoder(strings.NewReader(jsonstring))
dec.Decode(&data)
jq := jsonq.NewQuery(data)
```

From here, you can query along different keys and indexes:

```go
// data["foo"] -> 1
jq.Int("foo")

// data["subobj"]["subarray"][1] -> 2
jq.Int("subobj", "subarray", "1")

// data["subobj"]["subarray"]["array"][0] -> "hello"
jq.String("subobj", "subsubobj", "array", "0")

// data["subobj"] -> map[string]interface{}{"subobj": ...}
obj, err := jq.Object("subobj")
```

Missing keys, out of bounds indexes, and type failures are all returned in the
error channels. For simplicity, integer keys (ie, {"0": "zero"}) are inaccessible
by `jsonq` as integer strings are assumed to be array indexes.

Suggestions/comments please tweet [@jmoiron](http://twitter.com/jmoiron)

<commit_msg>remove inaccurate terminology 'error channel'<commit_after># jsonq

Simplify your golang json usage by extracting fields or items from arrays and
objects with a simple, hierarchical query. [API
Documentation](http://go.pkgdoc.org/github.com/jmoiron/jsonq) on go.pkgdoc.org.

# installing

```
go get github.com/jmoiron/jsonq
```

# usage

Given some json data like:

```javascript
{
	"foo": 1,
	"bar": 2,
	"test": "Hello, world!",
	"baz": 123.1,
	"array": [
		{"foo": 1},
		{"bar": 2},
		{"baz": 3}
	],
	"subobj": {
		"foo": 1,
		"subarray": [1,2,3],
		"subsubobj": {
			"bar": 2,
			"baz": 3,
			"array": ["hello", "world"]
		}
	},
	"bool": true
}
```

Decode it into a `map[string]interrface{}`:

```go
import (
	"strings"
	"encoding/json"
	"github.com/jmoiron/jsonq"
)

data := map[string]interface{}{}
dec := json.NewDecoder(strings.NewReader(jsonstring))
dec.Decode(&data)
jq := jsonq.NewQuery(data)
```

From here, you can query along different keys and indexes:

```go
// data["foo"] -> 1
jq.Int("foo")

// data["subobj"]["subarray"][1] -> 2
jq.Int("subobj", "subarray", "1")

// data["subobj"]["subarray"]["array"][0] -> "hello"
jq.String("subobj", "subsubobj", "array", "0")

// data["subobj"] -> map[string]interface{}{"subobj": ...}
obj, err := jq.Object("subobj")
```

Missing keys, out of bounds indexes, and type failures will return errors.
For simplicity, integer keys (ie, {"0": "zero"}) are inaccessible
by `jsonq` as integer strings are assumed to be array indexes.

Suggestions/comments please tweet [@jmoiron](http://twitter.com/jmoiron)


{'fraction_non_alphanumeric': 0.20398970398970398, 'fraction_numerical': 0.014157014157014158, 'mean_word_length': 4.4258289703315885, 'pattern_counts': {'":': 36, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4240037', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1145, 'n_words': 308}