Commit Graph

244 Commits

Author SHA1 Message Date
Josh Baker 3cd3a11923
Merge pull request #71 from speier/master
valid bytes method
2018-04-29 08:13:28 -07:00
speier 3a977634eb valid bytes method 2018-04-27 15:54:16 +02:00
Josh Baker 9ed3f8e1a5
Merge pull request #67 from bcho/patch-1
Add `arrayOrMap` result description
2018-03-01 11:15:57 -07:00
hbc 93d61e6369
Add `arrayOrMap` result description
Explain `Result.Value` will return array and map when possible.
2018-02-28 11:21:22 +08:00
Josh Baker 01f00f1296
Merge pull request #66 from Hexilee/master
Result.Bool() can parse 'false' as false
2018-02-23 08:48:56 -07:00
Hexilee 9fa9086994 Result.Bool() can parse 'false' as false 2018-02-23 20:25:48 +08:00
Josh Baker aff9dcea3c uncomment function 2018-02-18 10:09:03 -07:00
Josh Baker c2e370e1b3 comment on Valid 2018-02-18 10:05:23 -07:00
Josh Baker df0b0cce42
section on json validation 2018-02-18 09:49:01 -07:00
Josh Baker 46c712f1ce
update playground badge 2018-02-10 11:31:49 -07:00
Josh Baker 54d114d487
minor updates 2018-02-10 09:30:30 -07:00
Josh Baker 6d43584b26
mention related projects 2018-02-10 09:10:40 -07:00
Josh Baker 4b8623b9d6
minor edits 2018-02-09 19:51:56 -07:00
Josh Baker 749b396bb9
Update README.md 2018-02-09 16:09:45 -07:00
Josh Baker 077965694f
changed badge color 2018-02-09 16:08:32 -07:00
Josh Baker b9953e2865
Update README.md 2018-02-09 16:04:47 -07:00
Josh Baker a2f35b522e Added support for JSON Lines
Added support for JSON Lines (http://jsonlines.org) using the `..` prefix.
Which when specified, treats the multi-lined document as an array.

For example:

```
{"name": "Gilbert", "age": 61}
{"name": "Alexa", "age": 34}
{"name": "May", "age": 57}
{"name": "Deloise", "age": 44}
```

```
..#                   >> 4
..1                   >> {"name": "Alexa", "age": 34}
..3                   >> {"name": "Deloise", "age": 44}
..#.name              >> ["Gilbert","Alexa","May","Deloise"]
..#[name="May"].age   >> 57
```

Closes #60
2018-02-09 15:42:42 -07:00
Josh Baker 5fe9078c47
mention large integer support 2018-02-08 12:21:27 -07:00
Josh Baker bff3f07fe7
mention large integer support 2018-02-08 12:21:08 -07:00
Josh Baker 87033efcae array query mismatch, fixes #58 2018-01-23 05:45:05 -07:00
Josh Baker 5cd723d566 simplify getmanybytes 2017-12-22 07:19:48 -07:00
Josh Baker 62ee2064df remove commented line 2017-12-22 07:17:19 -07:00
Josh Baker 09641abb33 update tagline 2017-12-22 07:16:29 -07:00
Josh Baker e62d62a3e1 match GetMany and Get results, fixes #55 2017-12-22 06:58:04 -07:00
Josh Baker 080cd22816 fix mysterious missing result
fixes #54
2017-12-13 16:29:27 -07:00
Josh Baker 182ad76050 Array() from null becomes zero length Go array
fixes #53
2017-12-01 14:13:24 -07:00
Josh Baker 67e2a63ac7 Merge branch 'erikjohnston-fix-raw-false' 2017-11-20 11:50:05 -07:00
Erik Johnston 922b012d22 Fix bug where Result.Raw of literal 'false' was 'f' 2017-11-20 17:59:58 +00:00
Josh Baker ac7b6ae6f2 deprecated unmarshalling 2017-10-18 05:19:20 -07:00
Josh Baker 5a69e67cfd GetMany result value missing, fixes #48 2017-09-25 04:39:06 -07:00
Josh Baker 3c91814cf6 GetMany result incorrect, fixes #47 2017-09-25 04:37:57 -07:00
Josh Baker be96719f99 incomplete surrogate codepoints, fixes #38 2017-08-30 10:08:10 -07:00
Josh Baker 4e8f0c7f28 added playground link 2017-08-14 18:16:21 -07:00
Josh Baker ccc7f39b3a added IsObject IsArray helper functions 2017-08-14 08:23:21 -07:00
Josh Baker 6daf3373dc Moved benchmark code
Moved benchmark to a different repository to avoid the fetching of
unneeded imports. Please find these benchmarks at
https://github.com/tidwall/gjson-benchmarks
2017-08-14 08:21:16 -07:00
Josh Baker c784c41781 Allow parsing of large integers
This commit fixes an issue in which GJSON was not representing integers
correctly that were greater than 53-bits when calling the result.Int()
and result.Uint() functions. This happened because GJSON stored all
numbers as float64s in the result.Num field, and Int()/Uint() would
simply try to convert the float64 to int64/uint64 by issuing
int64(result.Num) or uint64(result.Num) operations.

Now rather than a simple cast, GJSON checks to see if the float64 is a
whole integer and if the integer can fit within 53-bits. If so, then
the cast method can be used. Otherwise GJSON attempts to parse the
result.Raw directly. If that fails too, it falls back to the original
method.

This fix should maintain compatibility with existing applications.

thanks @joelpresence for reporting
fixes #29
2017-05-25 19:39:18 -07:00
Josh Baker 0623bd8fbd Merge pull request #27 from kshvmdn/master
Minor README clean-up
2017-05-10 20:52:25 -07:00
Kashav Madan 8eb5c54ee3 Minor README clean-up 2017-05-10 23:42:56 -04:00
Josh Baker 617caec145 Update README.md 2017-05-08 21:47:28 -07:00
Josh Baker 2e78916f4a option to disable validation 2017-05-08 17:47:46 -07:00
Josh Baker 2555fc0b61 Unmarshal Validation
The Unmarshal function now returns an error if the JSON is not valid.
2017-05-08 17:33:03 -07:00
Josh Baker 0bedaf01cb updated wording 2017-05-08 07:47:07 -07:00
Josh Baker 371acf8f0c updated wording 2017-05-08 07:40:56 -07:00
Josh Baker 19194a58d8 typos 2017-05-08 06:55:29 -07:00
Josh Baker 3f5adf1ba9 New gjson.Unmarshal function
It's a drop in replacement for json.Unmarshal and you can typically see
a 3 to 4 times boost in performance without the need for external tools
or generators.

This function works almost identically to json.Unmarshal except that
it expects the json to be well-formed prior to being called. Invalid
json will not panic, but it may return back unexpected results.
Therefore the return value of this function will always be nil.

Another difference is that gjson.Unmarshal will automatically attempt
to convert JSON values to any Go type. For example, the JSON string
"100" or the JSON number 100 can be equally assigned to Go string,
int, byte, uint64, etc. This rule applies to all types.
2017-05-07 18:26:54 -07:00
Josh Baker e30a9c1037 Default String() to empty when nonexistent or null
This commit alters the behavior of string handling.

Prior to this change, calling result.String() for nonexistent and null
JSON members would return "null". This runs counter to the zero and omitempty
defaults of Go. Thus I've been seeing in the wild:

    s := result.String()
    if s == "null" || s == "" {
        // ... handle empty string condition
    }

Now we can simply write:

    if result.String() == "" {
        // ... handle empty string condition
    }

It's still possible to explicitly check for null and existence.

    result.Type == gjson.Null
    result.Exists()
2017-04-18 09:28:51 -07:00
Josh Baker 039b641eab added result.Time() function 2017-04-14 17:58:25 -07:00
Josh Baker 6e0babc7e8 updated benchmarks, added features list 2017-04-14 11:13:32 -07:00
Josh Baker a8ccb8767a mention "values" 2017-04-12 14:16:56 -07:00
Josh Baker 7d884e04ac minor update 2017-04-12 14:14:42 -07:00