JavaScriptExpression

Background & Context

    • Code representation format for the JavaScript programming language.
    • JavaScriptExpression is the same as the format RawJSON.
    • MIME type: application/json.
    • Data interchange format.
    • JavaScriptExpression supports full JSON syntax but uses a specific interpretation.
    • JavaScriptExpression 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","JavaScriptExpression"] imports a JSON file as a combination of nested lists and associations.
  • ImportString["string","JavaScriptExpression"] imports a JSON string.
  • Export["file",expr,"JavaScriptExpression"] exports a combination of nested lists and associations to a JSON file.
  • ExportString[expr,"JavaScriptExpression"] exports to a JSON string.
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport 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
  • Import uses the "Data" element by default.
  • The "JavaScriptExpression" format identifies JSON objects of the form {field1:value1,field2:value2,} with associations of the form <|"field1"->value1,"field2"->value2,|> in the Wolfram Language.
  • "JavaScriptExpression" identifies JSON lists [e1,e2,] with Wolfram Language lists {e1,e2,}.
  • Strings in the Wolfram Language are represented in JavaScriptExpression as UTF-8 strings, escaped as required by the JSON standard.
  • Numbers where scientific notation is used are given in JavaScriptExpression 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

Basic Examples  (3)

Import a JavaScript list:

Give a string consisting of a JavaScript object:

Importing this string gives an association:

Import a JavaScript expression from ExternalEvaluate using Node.js:

Confirm that it is the same as using the "ReturnType" of "Expression":

Evaluate a JavaScript object with ExternalEvaluate and import it as an association: