# File I/O

## General Parsing Function

WaterModels supports two input file formats: JavaScript Object Notation (JSON) and EPANET input file formats. The function below parses an input file based on its extension and returns a WaterModels data model in the form of a dictionary.

WaterModels.parse_fileFunction
parse_file(
path::String;
skip_correct::Bool=false,
per_unit::Bool=true
)

Parses an EPANET (.inp) or JavaScript Object Notation (JSON) file from the file path path, depending on the file extension, and returns a WaterModels data structure (i.e., a dictionary of data). Here, skip_correct will skip data correction routines (e.g., component status propagation) if set to true, and per_unit will translate the data model to a per-unit measurement system if set to true.

source

## General Data Formats

The JavaScript Object Notation (JSON) file format is a direct serialization of WaterModels' internal data model. As such, the JSON file format is intended to be a temporary storage format. WaterModels does not maintain backward compatibility with serializations of earlier versions of the WaterModels data model.

WaterModels.parse_jsonFunction
parse_json(path::String)

Parses a JavaScript Object Notation (JSON) file from the file path path and returns a WaterModels data structure (i.e., a dictionary of data). Does not perform data correction nor per-unit translations of the data model.

source

## EPANET Data Files

The EPANET (.inp) file format is the de facto standard for representing water networks. The function below parses the EPANET file at path path and returns a WaterModels data structure (a dictionary of data). See the OpenWaterAnalytics Wiki for a description of the EPANET format. Note also that this parsing routine does not preserve topology nor one-to-one correspondence with the original EPANET model. As one example, each pipe with a valve (check or shutoff) is transformed into a WaterModels pipe component and a valve component. As another example, WaterModels "nodes" are points at which junctions, reservoirs, or tanks appear in the EPANET model. In the WaterModels data model, junctions, reservoirs, and tanks are considered as "attached" to nodes.

WaterModels.parse_epanetFunction
parse_epanet(path::String)

Parses an EPANET (.inp) file from the file path path and returns a WaterModels data structure (a dictionary of data). See the OpenWaterAnalytics Wiki for a thorough description of the EPANET format and its components. Note also that this parsing routine does not necessarily preserve topology nor one-to-one correspondence with the original EPANET model, e.g., each pipe with a valve (check or shutoff) is transformed into a WaterModels pipe component and a valve component. Does not perform data correction nor per-unit translations of the data model.

source