Thread overview
[Issue 15884] Assigning char[] to std.json.JSONValue creates array, not string
Apr 06, 2016
Lionello Lunesu
Apr 09, 2016
b2.temp@gmx.com
Apr 12, 2016
Lionello Lunesu
Apr 12, 2016
Lionello Lunesu
Mar 21, 2020
Basile-z
April 06, 2016
https://issues.dlang.org/show_bug.cgi?id=15884

--- Comment #1 from Lionello Lunesu <lio+bugzilla@lunesu.com> ---
Ugh, I understand why it's the way it is.

Should we do .idup in JSONValue? Either way there's going to be an allocation, either for the JSONValue[] or for the string.

The repro might seem convoluted, but I ran into it like this: a method returns a char[], in order to give the caller full r/w control, which is what such a "toString" function is supposed to do. Using this return value (which thanks to "auto" is not obvious) in a JSONValue results in a less than ideal JSON.

--
April 09, 2016
https://issues.dlang.org/show_bug.cgi?id=15884

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com

--- Comment #2 from b2.temp@gmx.com ---
(In reply to Lionello Lunesu from comment #1)
> Ugh, I understand why it's the way it is.
> 
> Should we do .idup in JSONValue? Either way there's going to be an allocation, either for the JSONValue[] or for the string.
> 
> The repro might seem convoluted, but I ran into it like this: a method returns a char[], in order to give the caller full r/w control, which is what such a "toString" function is supposed to do. Using this return value (which thanks to "auto" is not obvious) in a JSONValue results in a less than ideal JSON.

I have tested a fix and calling idup doesn't break current tests, actually the method that's involved to make it accepts char[] is a template and with attribute inference there is no problem. It's always pure nothrow @safe, safe is a new requirement on the master version of std.json.

--
April 11, 2016
https://issues.dlang.org/show_bug.cgi?id=15884

--- Comment #3 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/329f068d7aedd0371b324c2676a4ebf75f3a4a13
fix issue 15884 - Assigning char[] to std.json.JSONValue creates array, not
string

https://github.com/D-Programming-Language/phobos/commit/ada161f0c571733aeb280566d6aff0af1e9396ad Merge pull request #4176 from BBasile/issue-15884

fix issue 15884 - Assigning char[] to std.json.JSONValue creates array, not string

--
April 11, 2016
https://issues.dlang.org/show_bug.cgi?id=15884

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--
April 12, 2016
https://issues.dlang.org/show_bug.cgi?id=15884

Lionello Lunesu <lio+bugzilla@lunesu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #4 from Lionello Lunesu <lio+bugzilla@lunesu.com> ---
Ah, you're fast, but what about wchar[] dchar[]? I suggest we use
std.utf.toUTF8() to handle all the non-string cases (it does a "idup" for
char[], by the way.)

--
April 12, 2016
https://issues.dlang.org/show_bug.cgi?id=15884

Lionello Lunesu <lio+bugzilla@lunesu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Lionello Lunesu <lio+bugzilla@lunesu.com> ---
I don't know how the link magic works, but here's the PR: https://github.com/D-Programming-Language/phobos/pull/4185

--
April 17, 2016
https://issues.dlang.org/show_bug.cgi?id=15884

--- Comment #6 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/1f1ed031a3215b3fa6585ccca189d68c1ad5b154 Fix issue 15884 Encode wstring/wchar[]/dstring/dchar[] as JSON string

https://github.com/dlang/phobos/commit/1f37557e38b787a021da1cce4c46c4c8ae131d04 Merge pull request #4185 from lionello/fix15884

Fix issue 15884 Encode wstring/wchar[]/dstring/dchar[] as JSON string

--
April 17, 2016
https://issues.dlang.org/show_bug.cgi?id=15884

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=15884

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--