Commit graph

206 commits

Author SHA1 Message Date
Martin Kinkelin
cafe864533
std.json: Avoid setting union members, set the whole union instead (#10683)
To work around https://github.com/dlang/dmd/issues/20675.
2025-03-17 22:24:14 +08:00
Iain Buclaw
d53b5636b2
std.json: Void initialize return value in emptyOrderedObject (#10617)
Works around issue seen in dlang/dmd#20675.
2025-01-11 05:51:56 +08:00
Vladiwostok
231ae8b68a
Fix D-Scanner linting issues (#9070)
* Fix UndocumentedDeclarationCheck linting issue

* Fix IfConstraintsIndentCheck linting issue

* Address feedback

* Fix publictests CI

* Fix old (libdparse) D-Scanner linting warn
2024-10-27 01:21:56 -07:00
Vladimir Panteleev
800dd75234
Move ordered object indication into a new bool
Avoid breaking code that do "final switch" oven JSONType.
2024-10-21 22:31:58 +00:00
Vladimir Panteleev
dfb9db4004
Fix Bugzilla 24823 - std.json: Allow optionally preserving the order of fields in JSON objects 2024-10-21 11:41:24 +00:00
Dennis
d5780aa8f5
std.json: Document opEquals (#8975)
Co-authored-by: Dennis Korpel <dennis@sarc.nl>
2024-07-19 10:52:14 +03:00
Jeremy Baxter
f31a7bc41d replace dead links
for link in $(grep -Eor 'https?://[^\\)", ]+' | grep -v dlang.org \
| grep -Eo 'https?://.+'); do (printf "%s: " "$link"; curl -Is "$link" \
| head -n1) | grep -E '4..$'; done

for link in $(grep -Eor '\\$\\(HTTP .+, ' | grep -v dlang.org \
| cut -d' ' -f2- | sed 's/, .*$//'); do out="$(curl -Is "$link")"; \
(! [ $? = 0 ] || printf '%s' "$out" | head -n1 | grep -Eq '4..') \
&& printf '%s\\n' "$link"; done
2024-07-14 15:16:11 +12:00
Jeremy
4203847ad6 Improve documentation in std.json 2023-09-10 16:59:21 +12:00
Mathis Beer
2649d6fe1b Add warning to std.json that it doesn't play well with the GC.
Production experience as well as synthetic tests have shown that std.json's use of associative arrays combined with GC issues causes heavy heap fragmentation. Furthermore, its heavy GC usage makes it unperformant in a threaded environment.
Despite this, people keep using std.json for production workloads, then being disappointed when it doesn't measure up. So let's warn them upfront.
2023-07-04 12:24:25 +02:00
Jeremy
3c74c2b88a
Add an introduction to the std.json documentation, fix some mistakes in std.curl and replace broken links in std.stdio (#8724)
* Fix some mistakes in curl.d

* Add an introduction for std.json

* Fix more documentation in curl.d

* Fix broken links in std.stdio documentation
2023-03-21 11:01:15 +02:00
Andrew Lalis
2f8dd14f8d
Add emptyObject() and emptyArray() functions to std/json (#8559)
* Added emptyObject() and emptyArray() functions, and tests for them.
2023-03-09 15:28:55 +08:00
Nick Treleaven
281f42d306
Fix missing unittests in docs (#8603)
* Fix missing staticArray unittest in docs

Found using https://github.com/dlang/dmd/pull/14527.

* Fix missing FloatRep and DoubleRep unittests in docs

* 2 JSONValue op overloads

* std.random

* detabber

* remove

* std.digest.murmurhash
2022-10-17 05:43:13 +08:00
Walter Bright
6b01031cb1
Update std/json.d
Co-authored-by: Dennis <dkorpel@users.noreply.github.com>
2022-08-12 08:36:12 -07:00
Walter Bright
c14a7e0368 replace delegate with simple nested function 2022-08-12 07:00:42 -07:00
Dennis Korpel
5636c8cdcc Fix incorrect return scope annotations 2022-03-22 18:08:31 +00:00
WebFreak001
dac59a4bde add isSomeFiniteCharInputRange as simplification
combines the very common constraint
`isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R)`
and adds a bunch of documentation with examples for users to understand
it better. This should lower the neccessary needed technical insight to
read basic docs, especially std.path and std.file docs.
2022-01-15 18:38:52 +01:00
dkorpel
ea76f45494 Use return scope instead of just return 2021-11-26 17:03:06 +01:00
dkorpel
cd7389266e Add explicit return to inout functions 2021-11-16 23:22:33 +00:00
giacomo.ratto00
1c57bbd58f indent with spaces 2021-08-28 19:52:28 +02:00
giacomo.ratto00
66c84669c0 Make JSONValue.opBinaryRight!"in" inout 2021-08-28 19:25:28 +02:00
Atila Neves
815a718c81 Fix static assert message in std.json 2021-06-08 15:12:25 +00:00
nordlow
450e79cd6a Annotate std/json.d to please dlang/dmd#12520 2021-05-18 11:02:18 +02:00
berni44
b2019ebab0 Narrow imports of std.math in the rest of phobos. 2021-04-21 03:00:57 +02:00
berni44
189a646286 Fix Issue 16432 - JSON incorrectly parses to string 2021-03-22 14:13:25 +01:00
berni44
6f2a0934a7 Adapt imports of std.format to new structure of std.format. 2021-03-19 13:22:00 +01:00
Crom (Thibaut CHARLES)
de28a13d54 Better wording & removed useless import 2020-12-03 19:42:10 +02:00
Crom (Thibaut CHARLES)
54c56ecb09 use std.conv.to to check for overflows 2020-12-03 19:42:10 +02:00
Crom (Thibaut CHARLES)
61a2fdd8f5 Add some conversions to JSONValue.get!T 2020-12-03 19:42:10 +02:00
Nathan Sashihara
453faadf5b Replace is(Unqual!T == Unqual!U) with is(immutable T == immutable U) for speed & memory usage 2020-08-03 15:07:32 +02:00
MoonlightSentinel
d816788da4
Fix Issue 20874 - std.json.assign requires '@safe' and 'pure' 2020-05-28 23:35:27 +02:00
Geod24
04f3979317 Replace 'Issue XXX' with Bugzilla links
Make the links clickable, as was done in the DMD repository.
Also avoids any ambiguity w.r.t. where the issue is stored.
2020-04-13 16:28:09 +09:00
aG0aep6G
9a91156f87 DRY 2020-03-10 02:40:07 +01:00
aG0aep6G
0bd2fa4334 mark access to value.store.str as @trusted
When issue 20655 ("attribute inference accepts unsafe union access as
@safe") is fixed, DMD correctly complains about the operation being unsafe.
2020-03-10 01:44:28 +01:00
Steven Schveighoffer
dbd4a2c0a5 Fix issue 20527. Set the correct union member for integers so CTFE
doesn't get confused.
2020-01-23 08:32:50 -05:00
Mathis Beer
3e26069a4f Fix issue 20511: make toJSON infer safeness based on output range safeness. 2020-01-17 06:26:51 +01:00
Martin Nowak
1589503ca0 Merge remote-tracking branch 'upstream/stable' into merge_stable 2019-12-16 10:52:16 +01:00
GrimMaple
8793b093bc Add get!(T) getter to std.json 2019-11-17 02:34:17 +03:00
Carsten Schlote
1479200267 Enhanced deprecation message on JSON_TYPE alias
Add hint to message to also change the enum members.
2019-11-03 11:39:29 +01:00
Carsten Schlote
ae03972df1 Fix Issue 20350 - Undeprecate JSONType member to avoid deprecation warnings
Undeprecate JSONType members, which create lots of spam-like
deprecation warnings, which can't be fixed by the user.

See discussion on this issue at
  https://forum.dlang.org/post/feudrhtxkaxxscwhhhff@forum.dlang.org
2019-11-03 11:39:12 +01:00
Robert Schadek
057d7ed326 Issue20330 json toString with OutRange
more style
2019-10-30 08:37:26 +00:00
Atila Neves
4cfef68d61 Replace in with const in preparation of dmd change
Changing dmd to implement `in` meaning `scope const` when DIP1000 is
selected causes Phobos to fail to compile. This changes Phobos in
preparation for that change.
2019-10-23 12:41:35 +02:00
Robert Schadek
53aa79c235 std_json allow trailing comma
* changelog
* annotate unittest
* with check for strict parsing
* tabs
2019-06-14 10:49:22 +01:00
Flying-Toast
11ebb6474b remove deprecated stuff in std.json 2019-05-18 21:23:42 -04:00
The Dlang Bot
76ef073df3
Merge pull request #6726 from FeepingCreature/fix/Issue-19297-handle-jsonvalue-signed-unsigned-comparison
Fix issue 19297: handle comparison of signed, unsigned and floating JSONValues as in D
merged-on-behalf-of: Vladimir Panteleev <github@thecybershadow.net>
2018-10-16 14:57:03 +02:00
Mathis Beer
b07b215424 Fix issue 19297: handle comparison of signed, unsigned and floating JSONValues 2018-10-11 10:47:28 +02:00
The Dlang Bot
3e3c65d9b9
Merge pull request #6682 from Erikvv/feature/json-boolean-getter-setter
Add a getter and setter for booleans in JSON
merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2018-08-28 11:07:03 +02:00
Erik van Velzen
1992afb4b1 Remove inout for JSON getters of value types 2018-08-27 20:50:35 -04:00
Erik van Velzen
8e8409f308 Add a getter and setter for booleans in JSON 2018-08-27 20:54:32 +02:00
Mathis Beer
fbd094737f Fix Issue 19135
Rewrite std.json.JSON_TYPE to be CamelCase with lowercase members, with underscore attached to avoid keyword collision.
Deprecate the old type via alias.
2018-08-08 08:34:00 +02:00
Tyler Knott
20353df3d9 Fix issue 16639 - Review std.json wrt this article on JSON edge cases and ambiguities
The test corpus provided at https://github.com/nst/JSONTestSuite/ revealed some issues with the std.json.parseJSON function. Since addressing some of the issues required parseJSON to reject input it previously accepted, I have added a new JSONOptions.strictParsing flag so callers can opt-in to the stricter parsing.

The issues, and how I've addressed them, are listed below (approximately from most severe to least):

Silently dropping ASCII NUL characters from strings:
n_string_unescaped_crtl_char.json

This is the most serious problem I found while fixing the test cases. The current implementation of parseJSON() uses a helper function called peekChar() which can store the next character to handle in a variable of type Char (an alias of the character type). Unfortunately it was using 0 to indicate it has not read a character yet so if an ASCII NUL (which will have the value 0) is present in the text and someone reads it with peekChar() then it will effectively be skipped over, which was happening in string and whitespace parsing.

I changed peekChar() to use a Nullable!Char as the temporary storage for the next character to disambiguate the case where there is no pending unconsumed character from the case where there is a pending unconsumed ASCII NUL. In strict mode JSON with unescaped ASCII NULs in strings will throw an exception while in non-strict mode the JSON will be accepted with the NUL included in the string value.

Failure to accept ASCII DEL (0x7f) unescaped in strings:
y_string_unescaped_char_delete.json
y_string_with_del_character.json

These were the only test cases that std.json rejected that it should have accepted. This issue was addressed by changing the string parsing logic to explicitly check for character values < 0x20 instead of using std.ascii.isControl (which also returned true for 0x7f), with a special exception for ASCII NULs in non-strict mode as mentioned above.

Parsing "true", "false", and "null" tokens case-insensitively:
n_structure_capitalized_True.json

In strict mode those tokens are now parsed case-sensitively.

Accepting control characters other than ' ', '\t', '\r', and '\n' as whitespace:
n_structure_null-byte-outside-string.json
n_structure_whitespace_formfeed.json

In strict mode only the listed characters are accepted as whitespace, while non-strict mode continues to use std.ascii.isWhite with an additional exception for ASCII NUL for a similar reason as the n_string_unescaped_ctrl_char.json case (the skipWhitespace() function used peekChar() so it didn't handle ASCII NULs consistently; non-strict mode after my changes is actually more permissive than the previous behavior but it is at least consistently permissive).

Silently accepting empty data:
n_structure_no_data.json

In strict mode an exception is now thrown instead of returning an empty value.

Failure to enforce that numbers beginning with 0 cannot have any additional digits in the non-fractional part:
n_number_-01.json
n_number_neg_int_starting_with_zero.json
n_number_with_leading_zero.json

An additional check is now performed in strict mode when the whole part of a number begins with zero to ensure trailing digits are not present.

Failure to check for trailing characters after parsing:
n_array_comma_after_close.json
n_array_extra_close.json
n_multidigit_number_then_00.json
n_object_trailing_comment.json
n_object_trailing_comment_open.json
n_object_trailing_comment_slash_open_incomplete.json
n_object_trailing_comment_slash_open.json
n_object_with_trailing_garbage.json
n_string_with_trailing_garbage.json
n_structure_array_trailing_garbage.json
n_structure_array_with_extra_array_close.json
n_structure_close_unopened_array.json
n_structure_double_array.json
n_structure_number_with_trailing_garbage.json
n_structure_object_followed_by_closing_object.json
n_structure_object_with_trailing_garbage.json
n_structure_trailing_#.json

An additional check is now performed in strict mode to ensure any trailing characters after the initial JSON value are only whitespace.

In addition to the above issues, parseJSON() will throw ConvException for numbers out of the range of double/long/ulong which was not previously documented. I have updated the ddoc comment to reference that exception.
2018-06-27 21:29:00 -05:00