Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)
WOLFRAM LANGUAGE IMPORT/EXPORT FORMAT

ExpressionJSON (.json)

  • Import and Export support ExpressionJSON.
  • ExpressionJSON provides lossless round-tripping of Wolfram Language expressions to and from JSON.
  • By default, Import and Export use the "JSON" format for files ending in .json, rather than the "ExpressionJSON" format.

BackgroundBackground

    MIME type: application/json.
    Data interchange format.
    ExpressionJSON provides a JSON representation of Wolfram Language expressions.
    JSON is commonly used in web programming.
    JSON is an acronym derived from JavaScript Object Notation.
    JSON is based on a subset of the JavaScript programming language.
    Plain text format.
    JSON was developed in 2001.
    JSON is published as RFC 4627.

Import and ExportImport and Export

  • Import["file","ExpressionJSON"] imports a file that uses the ExpressionJSON format, producing an ordinary Wolfram Language expression.
  • Export["file",expr,"ExpressionJSON"] exports an arbitrary expression to ExpressionJSON.
  • Elements of expressions are represented as follows in ExpressionJSON:
  • "string""'string'" (UTF-8, with JSON escaping)
    True, Falsetrue, false
    Nullnull
    symbol"symbol"
    f[e1,e2,,opt1val1,]["f",e1,e2,,["Rule",opt1,val1],]
  • Machine integers are represented literally. Larger integers are represented as "digits".
  • Machine-precision numbers are represented as JSON numbers using e notation.
  • Arbitrary-precision numbers are by default given as "number", where number is the InputForm representation of the number.

ElementsElements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings

OptionsOptions

  • Export options:
  • "Compact"Falsewhether to omit line breaks and tabs
    "NullSymbols"{}a list of symbols to represent as JSON null
    "PrecisionHandling"Truewhether to allow bignums or issue a message
  • "Compact"->n includes line breaks and tabs up to indent level n.

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

Import a JSON list:

In[1]:=
Click for copyable input
Out[1]=

Import a String:

In[2]:=
Click for copyable input
Out[2]=

Import a Quantity:

In[3]:=
Click for copyable input
Out[3]=

Export an expression to a JSON string:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Export a list while converting None to JSON null:

In[1]:=
Click for copyable input
Out[1]=

Export a list of numbers of arbitrary precision:

In[1]:=
Click for copyable input
Out[1]=

Export a list of numbers and issue an error if any of them is not a machine-precision number:

In[2]:=
Click for copyable input
Out[2]=

Control the output format with "Compact" to limit indentation:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2016
(10.4)