- 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.
Background & Context
- MIME type: application/json.
- Data interchange format.
- ExpressionJSON provides a JSON representation of Wolfram Language expressions.
- JSON is commonly used in web programming.
- Plain text format.
- JSON was developed in 2001.
- JSON is published as RFC 4627.
Import & 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, False true, false Null null symbol "symbol" (UTF-8) f[e1,e2,…,opt1val1,…] ["f",e1,e2,…,["Rule",opt1,val1],…]
- Machine integers are represented literally. Larger integers are represented as "digits".
- See the following reference pages for full general information:
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
- General Import elements:
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements
Basic Examples (5)
Import a String:
Import a Quantity:
Export a list while converting None to JSON null: