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 removes the reflect package to avoid using the
reflect.SliceHeader and reflect.StringHeader structures. Instead
new sliceHeader and stringHeader stuctures have been added with
the same layout expect that they intentionally expose the data
field as an unsafe.Pointer instead of a uintptr.
golang has several tools that already parse boolean values in the standard library.
Specifically strconv.ParseBool(string)
https://golang.org/pkg/strconv/#ParseBool
"ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error."
This change returns any matching ParseBool string to that boolean value, or if the string is not one of those values, the error being thrown, returns a false.
This commit allows for gjson and sjson to be supported in
WebAssembly `wasm` projects, but breaks compatibility for
anyone using gjson with older Google App Engine and GopherJS.
`@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
It's now possible to do a query like
topology.instances.#(service_roles.#(=="one"))#.service_version
On a JSON document such as
{
"topology": {
"instances": [{
"service_version": "1.2.3",
"service_roles": ["one", "two"]
},{
"service_version": "1.2.4",
"service_roles": ["three", "four"]
},{
"service_version": "1.2.2",
"service_roles": ["one"]
}]
}
}
Resulting in
["1.2.3","1.2.2"]
It now possible to select multiple independent paths and join
their results into a single JSON document.
For example, given the following JSON
{
"info": {
"friends": [
{"first": "Dale", "last": "Murphy", "age": 44},
{"first": "Roger", "last": "Craig", "age": 68},
{"first": "Jane", "last": "Murphy", "age": 47}
]
}
}
The path `[info.friends.0.first,info.friends.1.last]` returns
["Dale","Craig"]
Or path `{info.friends.0.first,info.friends.1.last}` returns
{"first":"Dale","last":"Craig"}
You can also rename Object members such as
`{"alt1":info.friends.0.first,"alt2":info.friends.1.last}` returns
{"alt1":"Dale","alt2":"Craig"}
Finally you can combine this with any GJSON component
`info.friends.[0.first,1.age]` returns
["Dale",68]
This feature was request by @errashe in issue #113.
A modifier is a path component that performs custom processing on
the json.
Multiple paths can be "chained" together using the pipe character.
This is useful for getting results from a modified query.
See the README file for more information.