This commit removes the automatic escaping of html characters,
effectively rendering JSON strings in the same way as is the
builtin Go encoder with SetEscapeHTML(false).
This should not affect the quality of the resulting JSON and
hopefully will not cause any downstream issues.
This commit adds the Escape function for escaping a path
component, making it possible to directly querying keys that have
special characters like dots.
```
json := `{
"user":{
"first.name": "Janet",
"last.name": "Prichard"
}
}`
user := gjson.Get(json, "user")
println(user.Get(gjson.Escape("first.name")).String())
println(user.Get(gjson.Escape("last.name")).String())
// Output:
// Janet
// Prichard
```
See #333
This commit adds the "@dig" modifier, which allows for searching
for values in deep or arbitrarily nested json documents
For example, using the following json:
```
{ "something": {
"anything": {
"abcdefg": {
"finally": {
"important": {
"secret": "password"
}
}
}
}
}
}
```
```
@dig:secret -> ["password"]
```
See #130
This commit fixes an issue with ~false where the it's value was
simply the opposite of ~true. Now ~false explicitly checks for
false-ish values.
Also added ~null and ~* for testing null-ish and non-existent
values.
see #327
The only purpose of using the built-in Go was to encode json
strings that had unicode or needed to escaped.
This commit adds the new function `AppendJSONString` which allows
for appending strings as their json representation to a byte
slice.
It's about 2x faster than using json.Marshal.
The new "@group" modifier allows for grouping arrays of objects.
For example, using the "@group" modifier on the following json...
{"id":["123","456","789"],"val":[2,1]}
will results in...
[{"id":"123","val":2},{"id":"456","val":1},{"id":"789"}]
This commit adds a two new functions of the Result type:
- Result.Path: Returns the original path of a `Result` that was
returned from a simple `Get` operation.
- Result.Paths: Returns the original paths of a `Result` that was
returned from a `Get` operation with a query.
See issue #206 for more details
The "@keys" and "@values" modifiers converts an object into an
array of its keys or values respectively.
Take this json for example:
{"first":"Tom","last":"Smith"}
@keys -> ["first","last"]
@values -> ["Tom","Smith"]
This feature was requested in #161.
This commit adds the uses the MatchLimit function, which it the
same as Match but will limit the complexity of the input pattern.
This is to avoid long running matches, specifically to avoid ReDos
attacks from arbritary inputs.
This commit adds the new tilde '~' operator, which when used will
convert a value to a boolean before comparison.
For example, using the following JSON:
{
"vals": [
{ "a": 1, "b": true },
{ "a": 2, "b": true },
{ "a": 3, "b": false },
{ "a": 4, "b": "0" },
{ "a": 5, "b": 0 },
{ "a": 6, "b": "1" },
{ "a": 7, "b": 1 }
{ "a": 8, "b": "true" },
{ "a": 9, "b": false }
{ "a": 10, "b": null }
{ "a": 11 }
]
}
You can now query for all true(ish) values:
vals.#(b==~true)#
Which returns:
[1,2,6,7,8]
Or all false(ish) values:
vals.#(b==~false)#
Which returns:
[3,4,5,9,10,11]
The last value which was non-existent is treated as "false"
This commit fixes an issue where a multires query on an empty
array will result in a non-existent (empty string) result.
For example `Get("[]", "#(key=value)#").Raw` resulted in an
empty string. But, it should actually result in the empty
array `[]`.
This commit updates the match package to v1.0.3, which includes
a fix to an issue where a pattern with lots of repetitive stars
will increasingly slow down a Match operation.
Fixes#195
`@flatten` Flattens an array with child arrays.
[1,[2],[3,4],[5,[6,7]]] -> [1,2,3,4,5,[6,7]]
The {"deep":true} arg can be provide for deep flattening.
[1,[2],[3,4],[5,[6,7]]] -> [1,2,3,4,5,6,7]
The original json is returned when the json is not an array.
`@join` Joins multiple objects into a single object.
[{"first":"Tom"},{"last":"Smith"}] -> {"first","Tom","last":"Smith"}
The arg can be "true" to specify that duplicate keys should be preserved.
[{"first":"Tom","age":37},{"age":41}] -> {"first","Tom","age":37,"age":41}
Without preserved keys:
[{"first":"Tom","age":37},{"age":41}] -> {"first","Tom","age":41}
The original json is returned when the json is not an object.
`@valid` Ensures that the json is valid before moving on. An
empty string is returned when the json is not valid, otherwise
it returns the original json.
This modifier returns the current element as-is and can be used
to retrieve the JSON document itself. It is equivalent to the `#/` JSON Pointer.
Closes#149