Commit Graph

107 Commits

Author SHA1 Message Date
tidwall 44b8c19d87 Minor update to test 2021-09-01 07:24:15 -07:00
Sebastian Spaink 7405f21134 Rename to indexes
Set to nil when modifiers used
2021-07-09 18:15:56 -05:00
Bas 7460ecfe69 Fix test 2021-07-01 06:00:44 -05:00
Bas 9b49f6eef5 Undo unnecessary change 2021-07-01 05:58:26 -05:00
Bas 73b86a9fc9 Support queries 2021-07-01 05:58:24 -05:00
Sebastian Spaink 34ea511746 Support getting index for hastags 2021-07-01 05:57:36 -05:00
tidwall 2feb4037b4 Fix escaped strings missing double quote
fixes #223
2021-06-30 13:18:28 -07:00
tidwall 7a0721334f Fix syntax 2021-05-14 09:02:12 -07:00
tidwall d7dbdd1d92 Add tilde boolean operator
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"
2021-05-14 08:53:58 -07:00
tidwall d9710733f0 Allow escaped string characters in query values
Fixes #215
2021-04-19 09:43:16 -07:00
tidwall d6d786db3c Remove dead code 2021-04-19 09:18:03 -07:00
tidwall dee0375ffd Fix negative without int part for valid
fixes #210
2021-03-28 18:30:25 -07:00
tidwall d6cb589fc4 Fix non-existent response from multires query on empty array
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 `[]`.
2021-03-25 15:31:00 -07:00
tidwall c75c954102 Fix mod flatten including non-existent arrays 2021-03-25 08:28:15 -07:00
tidwall d18e16d152 Allow chaining multipaths using the dot 2021-03-22 04:19:47 -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 2f043b7abd Adjusted test 2020-11-04 16:01:22 -07: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
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
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 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 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
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 6781e4ee59 Allow paren queries 2019-06-29 11:31:27 -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
tidwall e91a88bec4 Allow for chaining syntax in multi array 2019-06-28 04:41:32 -07:00
tidwall 6eb62ca33f Added new tests for deep selectors 2019-06-27 18:37:09 -07:00
tidwall 7660d0f79f Allow for pipe and dot mixing 2019-06-27 18:27:53 -07:00
tidwall 7b8705a6b6 Use 80 column width 2019-06-27 18:03:46 -07:00
tidwall b877bd43b1 Allow for chaining syntax in array subselects 2019-06-27 17:51:42 -07:00
tidwall 89b19799ff Fix non-existent selectors results 2019-06-27 15:50:15 -07:00
tidwall eee0b6226f Fixed chained array result 2019-02-16 19:06:55 -07:00
tidwall 1ed2249f74 Added modifiers and path chaining
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.
2019-02-16 18:29:39 -07:00
tidwall 5d7556ad3d Valid json optimization
Added ~20% performance boost be removing extra allocation when
Valid() is called with a json string.
2019-02-16 14:50:53 -07:00
tidwall 5a96cfda70 Added GopherJS support 2019-01-14 08:40:04 -07:00
thirstycoda cced0fa719 Added not like operator support to query 2018-10-28 00:20:01 +01:00
tidwall 1e3f6aeaa5 Fix leftover array and map values
fixes #81
2018-08-02 08:58:17 -07:00
Josh Baker f92dbfc6b2 Fix different reuslts on duplicate keys
fixes #79
2018-07-30 14:44:31 -07:00
Josh Baker ba784d767a Fix string output for large integers
This fix makes calling String() on a JSON Number return the original value
as it was represented in the JSON document for signed and unsigned integers.
This ensures that very big (plus-53bit) integers are correctly returned.
Floating points maintain their previous behavior [-+]?[0-9]*\.?[0-9]*.

closes #74
2018-07-10 18:10:33 -07:00