What's the difference between Developer`WriteRawJSONString[]
and ExportString[]
? I see it used a lot but don't see a difference:
1 Answer
$\begingroup$
$\endgroup$
There are some differences, but as user9490 mentioned, at some level they both might eventually use the same internal functionality. Here are the differences I found:
ExportString[_,"JSON"]
will export list of rules andAssociation
s as JSON-objects whileExportString[_,"RawJSON"]
andWriteRawJSONString
can't handle list of rules but only work withAssociations
as input.- there is a difference in how they treat non-ascii characters.
ExportString[_,"RawJSON"]
will handle that asWriteRawJSONString
does. I don't fully understand the details but think that whatWriteRawJSONString
andExportString[_,"RawJSON"]
do looks more consistent than whatExportString[_,"JSON"]
does. ExportString
is documented functionality whileDeveloper`WriteRawJSONString
is not documented and thus is more likely to be changed or to go away.ExportString
presumably does more validity checks- According to simple tests
WriteRawJSONString
has better performance than bothExportString[_,"JSON"|"RawJSON"]
.
temp = RandomReal[1, {400, 20, 20}]; Developer`WriteRawJSONString[temp] === ExportString[temp, "RawJSON"]
returnsTrue
. $\endgroup$Trace
output from the two:TracePrint[ Developer`WriteRawJSONString[{1, 2, 3}], TraceInternal -> True ]
versus theExportString
version, and it looks likeExportString
performs a bunch of validity checks, loads the format, then ends up using functions from theDeveloper`
package, notablyDeveloper`WriteRawJSONStream
$\endgroup$