.fw files.wiki
JSON

JSON Files

JavaScript Object Notation

JSON is a text-based data-interchange format for structured values such as objects, arrays, strings, numbers, booleans, and null.

JavaScript Object Notation (JSON)

Most common
Developer
Douglas Crockford; standardized by ECMA International and IETF
Category
Data & Text
MIME type
application/json
Format
Text
First released
2001
Latest version
RFC 8259 / ECMA-404 2nd edition
Open standard
Yes

JSON-LD 1.1

Developer
World Wide Web Consortium (W3C)
MIME type
application/ld+json
Format
Text
First released
2014
Latest version
JSON-LD 1.1
Open standard
Yes

GeoJSON

Developer
GeoJSON working group; standardized by IETF
MIME type
application/geo+json
Format
Text
First released
2008
Latest version
RFC 7946
Open standard
Yes

JSON Text Sequences

Developer
IETF
MIME type
application/json-seq
Format
Text
Magic bytes
1E
First released
2015
Latest version
RFC 7464
Open standard
Yes

Open a .JSON file online

Reading file…

What is a .JSON file?

.json files normally consist of JavaScript Object Notation, which is a language independent plain-text serialization that is used to create name/value pairs. ECMA-404 and the IETF RFC 8259 specify its usage today after the widespread adoption of JSON during the 2000s when Douglas Crockford introduced its specification. The RFC 8259 defines a .json text as not necessary to have fixed structure at root level since the top level JSON entity could be any object, an ordered sequence, a string, number, Boolean, or a value null. Therefore, .json file extensions exist in web APIs, configuration of applications, software packages, logs, export files, game saves, among others.

Several similar formats make use of this extension too. JSON-LD files might use .json when they possess terms from linked data such as "@context", "@id", and "@type" and they prefer another extension called .jsonld. GeoJSON data could be stored both with .json and with another common extension called .geojson but they should contain some key terms like type, Feature, FeatureCollection, geometry, coordinates, properties etc. Another format called JSON Text Sequences from the IETF includes every JSON text prepended with the specific byte 0x1E (record separator) in every text, so this data is streamed, not manually edited.

It means that for this group of extensions, opening a file in the text-editor and examining the domain-specific keywords is one of the most rapid ways.

How to open a .JSON file

Open a .JSON file on Windows

  1. 1 Go to the folder with your file in File Explorer. Usually, downloaded files end up in Downloads.
  2. 2 Double-click your .JSON file if you have an app for .json files on your computer. In case it does not open, move on to step three.
  3. 3 Right-click your .JSON file -> select Open with -> Choose another app.
  4. 4 Choose Visual Studio Code in the list (Windows 11: choose Always). For Windows 10 -> put a check on "Always use this app to open .json files" and click OK.

Still not opening? See common problems and fixes, or view it in your browser.

Programs for Windows

Open a .JSON file on macOS

  1. 1 In the Finder app, locate your .JSON file.
  2. 2 Just double-click your .JSON file in order to automatically launch the program which is connected with it.
  3. 3 Need another app on your Mac? Control-click the file (or right-click with a mouse). In the pop-up menu select Open With -> Visual Studio Code.
  4. 4 If it isn't in the list, choose Other… and find the application manually.

Still not opening? See common problems and fixes, or view it in your browser.

Programs for macOS

Open a .JSON file on Linux

  1. 1 Launch your file manager. Depending on the desktop it may be named Files (GNOME), Dolphin (KDE Plasma), Nemo (Cinnamon) or Thunar (Xfce).
  2. 2 Double-click the file.
  3. 3 Or choose another program by right-clicking the file -> Open With -> Visual Studio Code.
  4. 4 Install Visual Studio Code (if it is not installed on your computer) from the software centre, repository or Flathub.

Still not opening? See common problems and fixes, or view it in your browser.

Programs for Linux

Open a .JSON file on Android

  1. 1 Launch Files or another file management app.
  2. 2 In Downloads, find the .JSON file and open it by tapping.
  3. 3 A list of apps capable of opening the file will be shown. Tap Mozilla Firefox and press Always to permanently connect the file type with this app.
  4. 4 No apps able to open this file? Download Mozilla Firefox from the Google Play Store.

Still not opening? See common problems and fixes, or view it in your browser.

Programs for Android

Open a .JSON file on iPhone / iPad

  1. 1 Use the Files app and go to On My iPhone, iCloud Drive or Downloads.
  2. 2 Tap the .JSON file you want to open.
  3. 3 If the file can be opened by a built-in iOS app (supported format), it opens automatically.
  4. 4 Touch and hold the file to get the context menu -> choose Share -> select Mozilla Firefox from the list of apps.
  5. 5 If there is no such option, download the app first from the App Store and then tap the document again.

Still not opening? See common problems and fixes, or view it in your browser.

Programs for iPhone / iPad

Open a .JSON file online

  1. 1 Move to the online viewer at the top of this page.
  2. 2 Drag the file there or select it, and its contents will appear in your browser tab. The file is not uploaded.

Still not opening? See common problems and fixes, or view it in your browser.

Programs for Online

More details about opening .JSON files

In Windows, JSON files can be opened in Visual Studio Code, Notepad++, Sublime Text, Firefox, Chrome, Python, jq, QGIS, GDAL, and ArcGIS Pro. It is possible to use these applications for editing purposes and, besides that, Visual Studio Code, Notepad++ and Sublime Text provide syntax highlighting functionality, while Python and jq offer advantages if reformatting/validation is required. QGIS, GDAL, and ArcGIS Pro are appropriate solutions if one works with GeoJSON or other geographic JSON variants. So, the list of free tools includes free, Visual Studio Code, Sublime Text, QGIS, GDAL, Python, and jq, while Notepad++, Firefox and Chrome can be considered as free as well. Moreover, it should be mentioned that ArcGIS Pro is a paid one. On macOS, TextEdit is able to show little files, but larger/complex files can be handled with Visual Studio Code, Sublime Text, BBEdit, Python, jq, QGIS and GDAL. BBEdit has a free mode and a paid upgrade; the standard macOS viewer and TextMate are other free choices.

For Android, Linux, iOS and Firefox and Chrome browsers can read JSON content, but in order to see the whole structure properly you will need developer-focused editor. The application with application/json response is supposed to open in special internal JSON viewer while the .json file opened via browser interface is usually shown as plain text file in Chrome and Firefox. For GeoJSON, you'd better use QGIS, ArcGIS Pro or web map visualization app instead of general-purpose editors; and for JSON-LD there are RDF-related validators and editors, as far as they rely heavily on @context expansion.

Technical details

In essence, a JSON file is a plain text file and not a binary format. An arbitrary .json file usually does not contain any magic number; has no fixed structure for the file's header/footer; does not feature built-in folder hierarchy support; and lacks inherent file's structure compression features. The typical MIME type used for a JSON content is 'application/json'; other related file formats include 'application/ld+json' (JSON-LD), 'application/geo+json', (GeoJSON), and 'application/json-seq', (JSON Text Sequences).

Data model for JSON as described in the RFC 8259: objects, arrays, strings, numbers, true/false and null. Name keys for the objects' members are always presented by strings. Space characters out of the quotation can be used, which is usually spaces (spaces, tabs, etc.). No comments or trailing commas are acceptable in JSON; strings' escape sequences can be defined by using \t, ", \\, \uXXXX, \n. Direct Unicode presentation via code points can be provided in a file's string data using the UTF-8 text. In terms of the numbers, decimal notation can only be used in a standard JSON; there are no NaN nor infinity in JSON at all.

According to RFC 8259, JSON exchange across systems should use UTF-8 format of characters. However some older parsers might be able to parse text as UTF-16, UTF-32 as long as appropriate BOM is used for encoding definition. For .json files being not fixed with their header/footer, first meaningful byte could not be defined. JSON Text Sequences use RS delimiter and as a result, the start of this format's file can begin with 0x1E as its first byte in a case where the first record is after this delimiter in a stream.

JSON format provides neither specific schema for the files nor metadata area as well as it contains no explicit version value. JSON itself according to RFC 8259 and ECMA-404 second edition stays stable in syntax and it features JSON-specific profiles in terms of the JSON-LD 1.1 and GeoJSON as well. Parser implementations show various approaches with the duplicate objects' members handling, numeric precision and integers ranges; JSON file's size range might extend from several bytes in setting up to multiple gigabytes for various kinds of logs and export files.

How to convert .JSON files

Pretty-printing and minification of JSON values do not result in losing information as all they do is alter the whitespace of those files. If needed for validation or for reviewing purposes, python -m json.tool input.json output.json could be used for the same in Python while jq -c . input.json > output.json would work to trim down unnecessary whitespace for smaller sizes.

The CSV file can be produced easily if input is an array of objects with one level only. It could also be done through the following pattern: jq -r '(.[] | keys_unsorted) as $keys | $keys, (.[] | [.[$keys[]]]) | @csv' input.json > output.csv. The use of YAML would be a good solution as the format supports JSON natively as the subset of YAML version 1.2.

With yq -P -o=yaml input.json > output.yaml all data structure would get rewritten while there is no way to add anchor or comments to YAML from a source in JSON format. It is also possible to perform XML format conversion using the necessary library yet arrays, namespace, attributes, or mixed content would require a separate mapping rule. It might lead to loss of information during translation process back.

The following tools could be used to translate to GeoPackage, KML, Shapefile, PostGIS among other formats - ogr2ogr. JSON-LD might be rewritten as Turtle, N-Quads, expanded, compacted and RDF/XML using respective software. To convert JSON file into Excel, first it should get normalized as a rectangular table while renaming alone would not help at all.

Convert toToolCommand / note
Pretty-printed JSON Python python -m json.tool input.json output.json Validates syntax and rewrites with indentation; object member order may be preserved by modern Python but semantic JSON order is not significant.
Minified JSON jq jq -c . input.json > output.json Removes insignificant whitespace while preserving JSON values.
CSV jq jq -r '(.[] | keys_unsorted) as $keys | $keys, (.[] | [.[$keys[]]]) | @csv' input.json > output.csv Works for a top-level array of similarly shaped objects; nested objects and arrays must be flattened or are serialized as strings.
YAML yq yq -P -o=yaml input.json > output.yaml YAML can represent JSON values directly, but comments cannot be recovered because JSON has none.
GeoPackage from GeoJSON JSON GDAL ogr2ogr ogr2ogr -f GPKG output.gpkg input.json Applies when the .json file is valid GeoJSON; coordinate reference system assumptions follow RFC 7946 unless overridden by the tool.
ESRI Shapefile from GeoJSON JSON GDAL ogr2ogr ogr2ogr -f 'ESRI Shapefile' output_directory input.json Shapefile has strict field-name, type, geometry, and size limitations, so attributes or geometry detail may be truncated.
RDF N-Quads from JSON-LD jsonld-cli jsonld toRDF input.json -q > output.nq Applies to JSON-LD documents; compaction context and JSON layout are not preserved in RDF output.

Common problems and fixes

Most of the common JSON errors usually mean something wrong with the syntax. In JavaScript, the error "unexpected token" usually means that there are some nonvalid JSONs like HTML error pages in .json file extension, comments, or trailing comma after the last item. Error “Expecting property name enclosed in double quotes” usually means that your file was written not as JSON but as JavaScript Object Literal with not-quoting of the keys of strings which is forbidden by the syntax of RFC 8259.

Errors "Extra Data" and "Multiple JSON Values" appear when some parser expects only one complete JSON and you are working on a newline JSON file or JSON Text Sequences (RFC 7464) file. To fix this problem, just find another parser which can recognize these formats, or just split up those records before importing. Sometimes encoding issues appear in the way of replacing character, parsing error around BOM mark and something like control characters in strings. Try to resave the files as UTF-8 format and to delete those illegal bytes like tabulation marks, line feeds and so on.

When .json is quite big, it can freeze some programs (Visual Studio Code, Chrome, Firefox, online file-viewer etc.) so try to use some tools like jq, some streaming features of Python language, some database utilities to import the content of the JSON file without opening in a GUI, or split the JSON file. Most of the parsers accept the duplicate object key, but keep just the last one, so validate the source before the importing procedure. When it comes to GeoJSONs it might be opened successfully but the coordinates of objects in this file might be incorrect because of the wrong order of latitude and longitude or incompatible CRS.

Security considerations

JSON is not equipped with any features like macros, execs, scripts, or automatically executing code in RFC 8259 data. However, JSON can become dangerous if read by a vulnerable parser or host application due to deserialization, prototype pollution, command injection, SQL injections, and other harmful procedures which exhausts program resources and becomes hazardous. It is necessary to always use a dedicated JSON parser to avoid passing JSON to eval - use JSON.parse, Python json, Jackson/Gson for Java programs, or use serde_json and jq library.

JSON that is big or too deep may consume excessive memory, produce stack overflows, and take too much time to parse. Thus one needs to impose maximums on their depth and validation time and also use strict parsing in case one does not want any unknown JSON features used. The content of JSON can include secrets such as API keys, access tokens, cookies, password, GPS coordinates and many others and GeoJSON could include coordinates too as well as travel routes and boundary lines. JSON-LD could load a malicious context when using noncached contexts.

History and versions

"JSON grew out of JavaScript object literal notation and was promoted by Douglas Crockford in about 2001 and served as an easy replacement to XML." Description of json.org contributed greatly to the swift adoption of JSON in the initial generation of AJAX applications around the first half of the decade beginning in the year 2000. In 2006 RFC 4627 defined application/json and limited a JSON text either to be a single object or array at the highest level.

"The 2013 specification ECMA-404 provides a compact and formally precise definition of JSON syntax." The 2014 document "RFC 7159 removes the top-level restrictions on the JSON text." RFC 8259 released later in 2017 supersedes RFC 7159 and defines JSON at IETF as Internet Standards-track standard. JSON specification also exists as standardized document at ECMA International with ECMA-404, 2nd edition, currently active. JSON-LD became a W3C Recommendation in 2014 whereas version 1.1 was published in 2020. "JSON-LD can represent graph structure as required by the semantic web" alongside schema.org annotations. GeoJSON came up as community specification back then in 2008 and was specified at IETF in 2016 through RFC 7946.

While XML files use Extensible Markup Language, can have attributes, namespaces, schemas, and allow mixed content, those properties are not available within JSON files. The downside is the size, where typically .xml would contain many more characters than a typical .json file. YAML files (.yaml, .yml) have human-editable syntax and allow comments as well as anchors, but have a parsing grammar that is somewhat complex and in the old times have been a source of vulnerability in code parsing. TOML files (.toml), used mostly for configuration, as well, have comments and clearly defined scalars. However, they would be better suited for relatively simple hierarchical structures than for deeply nested content. CSV files (.csv) allow a succinct representation and can handle rectangular tables, however, cannot naturally store nested objects or arrays. JSON Lines, i.e., .jsonl or .ndjson files hold one JSON object per line in place of the usual single top-level JSON array. Make sure you use specific file formats in case of GIS (GeoJSON, .geojson) or linked-data/JSON-LD (.jsonld), respectively. Binary formats such as .cbor, .bson, .msgpack, and .avro trade human readability for smaller size, faster parsing, schemas, or richer types.

Comments (0)

Replying to

No comments yet. Be the first to share your experience with this file type.