What's the difference between Developer`WriteRawJSONString[] and ExportString[]? I see it used a lot but don't see a difference:
Asked
Active
Viewed 102 times
4
M.R.
- 31,425
- 8
- 90
- 281
1 Answers
4
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 andAssociations as JSON-objects whileExportString[_,"RawJSON"]andWriteRawJSONStringcan't handle list of rules but only work withAssociationsas input.- there is a difference in how they treat non-ascii characters.
ExportString[_,"RawJSON"]will handle that asWriteRawJSONStringdoes. I don't fully understand the details but think that whatWriteRawJSONStringandExportString[_,"RawJSON"]do looks more consistent than whatExportString[_,"JSON"]does. ExportStringis documented functionality whileDeveloper`WriteRawJSONStringis not documented and thus is more likely to be changed or to go away.ExportStringpresumably does more validity checks- According to simple tests
WriteRawJSONStringhas better performance than bothExportString[_,"JSON"|"RawJSON"].
Albert Retey
- 23,585
- 60
- 104

temp = RandomReal[1, {400, 20, 20}]; Developer`WriteRawJSONString[temp] === ExportString[temp, "RawJSON"]returnsTrue. – Jason B. Jan 03 '17 at 21:38Traceoutput from the two:TracePrint[ Developer`WriteRawJSONString[{1, 2, 3}], TraceInternal -> True ]versus theExportStringversion, and it looks likeExportStringperforms a bunch of validity checks, loads the format, then ends up using functions from theDeveloper`package, notablyDeveloper`WriteRawJSONStream– Jason B. Jan 03 '17 at 22:12