RawJSON (.json)
- Import and Export support RawJSON.
- By default, Import and Export use the "JSON" format for files ending in .json, rather than the "RawJSON" format.
Background & Context
-
- MIME type: application/json.
- Data interchange format.
- RawJSON supports full JSON syntax but uses a specific interpretation.
- RawJSON identifies JSON objects with Wolfram Language associations.
- 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","RawJSON"] imports a JSON file as a combination of nested lists and associations.
- ImportString["string","RawJSON"] imports a JSON string.
- Export["file",expr,"RawJSON"] exports a combination of nested lists and associations to a JSON file.
- ExportString[expr,"RawJSON"] exports to a JSON string.
- 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 - Data representation element:
-
"Data" contents of a JSON file as nested lists or associations "Dataset" contents of a JSON file as a Dataset - Import by default uses the "Data" element.
- The "RawJSON" format identifies JSON objects of the form {field1:value1,field2:value2,…} with associations of the form <"field1"->value1,"field2"->value2,… > in the Wolfram Language.
- "RawJSON" identifies JSON lists [e1,e2,…] with Wolfram Language lists {e1,e2,…}.
- Strings in the Wolfram Language are represented in RawJSON as UTF-8 strings, escaped as required by the JSON standard.
- Numbers where scientific notation is used are given in RawJSON in E notation.
- The symbols True and False are represented in RawJSON as the values true and false.
- The symbol Null is represented as the JSON value null.
Options
- Export options:
-
"Compact" False whether to omit line breaks and tabs "ConversionFunction" None function to apply for additional conversions "ConversionRules" {} rules to apply to override or add conversions - The setting for "ConversionRules" is used to replace subexpressions before built-in conversions are performed.
- The setting for "ConversionFunction" is applied to subexpressions for which no built-in conversion is defined.
- "Compact"->n includes line breaks and tabs up to indent level n.
Examples
open allclose allBasic Examples (9)
Give a string consisting of a JSON object:
Importing this string gives an association:
Import the contents of a JSON file:
Export an expression to a JSON string:
Export a list of chemical elements and their properties to a JSON file:
Use conversion function to format dates to ISO 8601:
Use conversion rules to transform rules and quantities:
Control the output format with "Compact", to limit indentation:
Import Elements (2)
"Dataset" (1)
Import a JSON file as a Dataset: