RawJSON (.json)

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 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"Falsewhether to omit line breaks and tabs
    "ConversionFunction"Nonefunction 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 all

Basic Examples  (9)

Import a JSON list:

Give a string consisting of a JSON object:

Importing this string gives an association:

Import the contents of a JSON file:

Import a URL:

Export an expression to a JSON string:

Export a list of chemical elements and their properties to a JSON file:

Export to a string:

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:

Scope  (1)

Create a compact string representation of a JSON file:

Import Elements  (2)

"Data"  (1)

Import a JSON file as nested associations:

"Dataset"  (1)

Import a JSON file as a Dataset: