Wolfram Language & System 10.4 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

RawJSON (.json)

  • Import and Export support RawJSON.
  • By default, Import and Export use the "JSON" format for files ending in , rather than the "RawJSON" format.
  • BackgroundBackground

      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 and ExportImport and 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 main function pages for full general information on Import and Export.
    • ImportString and ExportString support the RawJSON data format.

    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
    • Data representation element:
    • "Data"contents of a JSON file as nested lists or associations
    • Import by default uses the element.
    • The "RawJSON" format identifies JSON objects of the form with associations of the form in the Wolfram Language.
    • "RawJSON" identifies JSON lists with Wolfram Language lists .
    • 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 and .
    • The symbol Null is represented as the JSON value .

    OptionsOptions

    • Export options:
    • "Compact"Falsewhether to omit line breaks and tabs
    • The setting for is used to replace subexpressions before built-in conversions are performed.
    • The setting for is applied to subexpressions for which no built-in conversion is defined.
    • "Compact"->n includes line breaks and tabs up to indent level n.

    ExamplesExamplesopen allclose all

    Basic Examples  (9)Basic Examples  (9)

    Import a JSON list:

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

    Give a string consisting of a JSON object:

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

    Importing this string gives an association:

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

    Import the contents of a JSON file:

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

    Import a URL:

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

    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 of chemical elements and their properties to a JSON file:

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

    Export to a string:

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

    Use conversion function to format dates to ISO 8601:

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

    Use conversion rules to transform rules and quantities:

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

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

    In[1]:=
    Click for copyable input
    Out[1]=
    Introduced in 2015
    (10.2)