Why convert NC to JSON?
JSON is the native data exchange format for web applications and REST APIs. Exporting a subset of climate or oceanographic data from a netCDF file as JSON lets web visualizations and services consume it without a netCDF library. It is also human-readable, making it useful for inspecting metadata or a small variable slice during development.
How to convert NC to JSON
Python (xarray + netCDF4) FREE
Install with pip install xarray netCDF4, open the file with xarray.open_dataset(), select the variable and slice with .sel(), then call .to_dict() and json.dump() to write the output.
ncdump FREE
Run ncdump -h data.nc to inspect metadata or ncdump -v variable_name data.nc to dump a variable in CDL text format; pipe through a Python one-liner to produce JSON output.
About these formats
An .nc file is a netCDF (Network Common Data Form) file - a binary format for multidimensional scientific data such as climate, weather, and ocean datasets from NOAA, NASA, and Copernicus.…
Open .NC details →A JSON file is a plain-text data file in JavaScript Object Notation format, used by web APIs, app configurations, and data exports. Any text editor opens it - Notepad on Windows, TextEdit…
Open .JSON details →Quality & what to watch
- JSON is practical only for small slices - a single global gridded variable at daily resolution can contain millions of numeric values, making the output slow to produce and difficult to consume.
- Always identify variable names first by running
ncdump -h yourfile.ncorprint(ds)in xarray before attempting any export. - For a flat, records-oriented structure suitable for REST APIs, use
subset.to_dataframe().reset_index().to_json(orient='records')instead of.to_dict().
Frequently asked questions
Can I convert the entire NC file to a single JSON document?
Is there an online tool to convert NC to JSON?
What JSON structure does xarray produce?
.to_dict() outputs a nested object with keys for coords, data_vars, dims, and attrs, mirroring the xarray Dataset structure.