ExpressionJSON (.json)
ExpressionJSON (.json)
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.
- 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 & 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
Import Elements
- 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
Examples
Basic Examples (5)
ImportString["[ \"List\", 1, 2, 3 ]", "ExpressionJSON"]Import a String:
ImportString["\"'abc'\"", "ExpressionJSON"]Import a Quantity:
ImportString["[ \"Quantity\", 2.45, \"'Meters'\"]", "ExpressionJSON"]Export an expression to a JSON string:
ExportString[{1, 2, 3}, "ExpressionJSON"]ExportString[<|"x" -> 1, "y" -> 2, "z" -> 3|>, "ExpressionJSON", "Compact" -> True]Export a list while converting None to JSON null:
ExportString[{True, None}, "ExpressionJSON", "NullSymbols" -> {None}]Export a list of numbers of arbitrary precision:
ExportString[
<|"PlanckConstant" -> 6.626070040 * 10 ^ −34, "AvogadroConstant" -> 6.02214 * 10 ^ 23, "Pi" -> N[Pi, 20]|>, "ExpressionJSON"]Export a list of numbers and issue an error if any of them is not a machine-precision number:
ExportString[<|"PlanckConstant" -> 6.626070040 * 10 ^ −34, "AvogadroConstant" -> 6.02214 * 10 ^ 23, "Pi" -> N[Pi, 20]|>, "ExpressionJSON", "PrecisionHandling" -> False]Control the output format with "Compact" to limit indentation:
ExportString[<|"x" -> {{1, 2}, {3, 4}}, "y" -> {{Null}}|>, "ExpressionJSON", "Compact" -> 2]Related Workflows
- Generate JSON
Related Workflows
▪
History
Introduced in 2016 (10.4)