JSON (.json)

MIME type: .
Data interchange format.
Commonly used in web service implementations.
Contains collections of unordered name-value pairs or ordered values.
JSON is an acronym derived from JavaScript Object Notation.
Based on a subset of the JavaScript programming language.
Plain text format.
Developed in 2001.
Published as RFC 4627.

Import and ExportImport and Export

  • Import["file.json"] gives a rule-based representation of a JSON file.
  • Export["file.json", expr] exports a list of rules to JSON.
  • Import["file.json", "elem"] imports the specified element from a JSON file.
  • Import["file.json", {"elem", "sub", ...}] imports a subelement.
  • Import["file.json", {{"elem1", "elem2", ...}}] imports multiple elements.
  • The import format can be specified with Import["file", "JSON"] or Import["file", {"JSON", elem, ...}].
  • Export["file.json", expr, "elem"] creates a JSON file by treating expr as specifying element elem.
  • Export["file.json", expr, opt1->val1, ...] exports expr with the specified option elements taken to have the specified values.
  • Export["file.json", {"elem1"->expr1, "elem2"->expr2, ...}, "Rules"] uses rules to specify the elements to be exported.
  • See the main function pages for full general information on Import and Export.
  • ImportString and ExportString support the JSON data format.


  • 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 rules
  • Import by default uses the element.
  • When importing from JSON, lists are returned in standard Mathematica sorting order.


  • Export option:
  • "Compact"Falsewhether to use line breaks to format file content

ExamplesExamplesopen allclose all

Basic Examples (2)Basic Examples (2)

Import the contents of a JSON file:

Click for copyable input

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

Click for copyable input

Create a compact string representation of a JSON file:

Click for copyable input
New in 8
New to Mathematica? Find your learning path »
Have a question? Ask support »