# JSON output

MC Grating writes its results as JSON as well as text since the 2021 releases: diffraction efficiencies and amplitudes for all six codes, optional diffraction angles, and since 2021-09-11 the field components of 1D and 2D scans in a single file.

Canonical: https://mcgrating.com/features/json-output.html


Every result the codes produce as a text table is also available as JSON, for scripts, notebooks and other programs.

## What is written

The codes keep the complete result of a calculation in memory and display it as a text table whose precision and diffraction orders the user can change without recalculating; the [Graph](https://mcgrating.com/docs/common/graph.html) tools read from that table. JSON output writes the same data to a file in a form a program can read directly. The changelog records it in three steps:

- [2021-05-10](https://mcgrating.com/changelog.html#v2021-05-10): JSON output is now available for all codes. Format is slightly changed, Diffraction Angles output is now optional. Can be enabled in GUI via 'Diffraction Angles' checkbox.
- [2021-09-11](https://mcgrating.com/changelog.html#v2021-09-11): Field calculation and output code have been rewritten with some speed optimizations. JSON output is now available for fields. All field components are saved in a single file both for 1D and 2D scanning.
- [2022-04-22](https://mcgrating.com/changelog.html#v2022-04-22): a fix for the 1D field scan output to JSON.

## What it pairs with

The [Advanced Output](https://mcgrating.com/docs/common/advanced-output.html) feature adds user-defined columns, computed by formulas from the diffraction orders and the scanning argument, to the same result table; [Advanced Scanning](https://mcgrating.com/docs/common/advanced-scanning.html) defines the scan itself from a table or equations. Together with JSON output they make a scan reproducible from a file and readable by a script; for Modal Crossed there is also the [Python interface](https://mcgrating.com/features/python-api.html).

The output format is not described in the in-application help, last revised in 2018; the changelog entries above are the record. The results text table and its options are documented under [Project window and menus](https://mcgrating.com/docs/modal/menus.html).
