Commit Graph

216 Commits

Author SHA1 Message Date
tidwall 65353b6d52 Removed reflect package
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.
2021-01-30 12:50:49 -07:00
tidwall 97ec619cbe Restrict pretty indent and prefixes to whitespace 2020-12-25 06:42:20 -07:00
tidwall bf4efcb3c1 Fix slice out of bounds panic
fixes #196
2020-12-24 09:51:53 -07:00
tidwall 9f58baa7a6 Update the match package
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
2020-12-23 05:00:23 -07:00
tidwall f0ee9ebde4 Fix bounds out of range panic
This commit fixes an issues where gjson panics when the input json
or path ends in incomplete quoted string.

fixes #192
2020-12-07 05:25:20 -07:00
tidwall 5100d6926a Better safe integer range for numbers
This commit optimizes the safe float to int conversion function
by using the full -9007199254740991 to 9007199254740991 range as
suggested at:

https://tc39.es/ecma262/#sec-number.min_safe_integer

closes #174
2020-11-04 16:26:43 -07:00
tidwall 2f043b7abd Adjusted test 2020-11-04 16:01:22 -07:00
tidwall 71341b2042 Use lowercase string booleans 2020-11-04 15:59:08 -07:00
tidwall eeddc5431f Merge branch 'deef0000dragon1-deef0000dragon1-ParseBool' 2020-11-04 15:54:24 -07:00
tidwall ed7c6c18ed Merge branch 'deef0000dragon1-ParseBool' of https://github.com/deef0000dragon1/gjson into deef0000dragon1-deef0000dragon1-ParseBool 2020-11-04 15:53:35 -07:00
Josh Baker 20b6add63a
Merge pull request #163 from Jalitha/patch-1
Fix typo in .Get comment
2020-11-04 15:12:32 -07:00
Josh Baker 140bf1266f
Merge pull request #179 from ader1990/master
Fixed small readme typos
2020-11-04 15:11:47 -07:00
Josh Baker 37d86694e2
Create go.yml 2020-11-03 11:38:19 -07:00
Josh Baker 23c5e2620b
Delete .travis.yml 2020-11-03 11:38:11 -07:00
Josh Baker 393cb5c3a9
Update README.md 2020-11-03 11:37:58 -07:00
tidwall 45d8d3b98f Updated pretty package 2020-08-28 08:14:33 -07:00
Adrian Vladu 2679aa886d
Fixed small readme typos 2020-07-27 18:31:55 +03:00
Jeffrey Koehler 78a59792a3 add test of different strings
Added test for each of the different accepted values for ParseBool, and a few arbitrary results that should return false.
2020-05-30 06:34:47 -04:00
deef 7db3b02e3f
update Result.Bool to use golang bool parsing
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.
2020-05-30 06:16:06 -04:00
Jalitha 65616e6f35
Fix typo in .Get comment 2020-04-20 21:10:36 +10:00
tidwall f042915ca1 Remove custom appengine and js builds
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.
2020-02-28 09:37:46 -07:00
Josh Baker c041e47f8a
Merge pull request #155 from Prithvipal/master
Fixed syntax document for escape character
2020-02-22 11:09:40 -07:00
Prithvipal Singh 1879ad91cd Addressed review suggestion 2020-02-22 23:25:31 +05:30
Prithvipal Singh 0439aef712 Fixed syntax document for escape character 2020-02-22 22:50:13 +05:30
tidwall 0360deb6d8 Added new modifiers
`@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.
2020-02-10 11:13:30 -07:00
tidwall d10932a0d0 Removed unmarshalling 2020-01-20 12:32:37 -07:00
tidwall 12826915de Removed unneeded comment 2020-01-20 08:29:11 -07:00
Josh Baker c9f07c7971
Merge pull request #150 from ory/add-this
Add @this modifier
2020-01-20 08:25:07 -07:00
aeneasr 8e8823353c
Add @this modifier
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
2020-01-20 15:01:54 +01:00
tidwall 5c2e4b3824 Fixed modifier pipe issue
This commit fixes an issue where chaining modifiers that used a
string arg would fail to process the modifier following the first.

fixes #143
2019-11-18 09:51:37 -07:00
tidwall c34bf81952 Fix trailing multiselector value 2019-11-02 14:52:36 -07:00
tidwall 94e070960b Add link to multipaths 2019-11-01 05:15:58 -07:00
tidwall 1471a933ec Rename test 2019-11-01 05:15:43 -07:00
tidwall 1c258afe09 Allow for modifiers in sub-selectors 2019-11-01 05:08:48 -07:00
tidwall c5e72cdf74 Fix panic when key starts at-sign 2019-07-15 07:54:43 -07:00
tidwall dea71f728d Mention nested queries 2019-07-12 06:46:38 -07:00
tidwall 1e964df7d9 Support subqueries
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"]
2019-07-12 06:14:45 -07:00
Josh Baker 90ca17622f
Update SYNTAX.md 2019-07-10 15:00:07 -07:00
tidwall 4d138e058b Add multipath syntax 2019-06-30 12:59:56 -07:00
tidwall d7c940e593 Fix missing raw result for array counts 2019-06-30 04:48:53 -07:00
tidwall 3b5bf6bb5e Added Subselectors
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.
2019-06-29 15:23:32 -07:00
tidwall 001444ea45 Remove the DisableChaining option
Chaining (pipe character) is now a part of the standard
2019-06-29 12:10:41 -07:00
tidwall 6781e4ee59 Allow paren queries 2019-06-29 11:31:27 -07:00
tidwall f8322e865d Rename file 2019-06-28 17:18:24 -07:00
Josh Baker f7c1980254
Update README.md 2019-06-28 17:17:38 -07:00
Josh Baker ae482cd23d
Update README.md 2019-06-28 17:16:29 -07:00
Josh Baker f73dd9bfd8
Create PATH-SYNTAX.md 2019-06-28 17:11:56 -07:00
tidwall ebf0b3fb77 Use no path for simple value queries 2019-06-28 10:18:23 -07:00
tidwall 00b15d756e Added querying array values 2019-06-28 05:55:18 -07:00
tidwall d95cbcaa9d Require multiarr results to always exist 2019-06-28 05:24:28 -07:00