... | ... | @@ -2,13 +2,27 @@ |
|
|
|
|
|
## Introduction
|
|
|
|
|
|
As an example of Parabix methods, consider the task of converting CSV (Comma-Separated
|
|
|
Value) files to JSON format (JavaScript Object Notation).
|
|
|
|
|
|
The overall structure of CSV to JSON conversion has 3 phases.
|
|
|
1. Determination of the CSV to JSON translation scheme for the particular file to be converted.
|
|
|
This scheme identifies the number of fields in each record, the corresponding field names for
|
|
|
JSON attributes and any other parameters that govern the translation.
|
|
|
This scheme identifies the number of fields in each record, the corresponding field names for JSON attributes and any other parameters that govern the translation.
|
|
|
2. Parsing the CSV input to determine the records and fields.
|
|
|
3. Transforming the parsed input according to the scheme to produce JSON output.
|
|
|
|
|
|
## Simple Universal Translation Scheme
|
|
|
|
|
|
One possible translation scheme for CSV to JSON is straightforward and universally
|
|
|
applicable to produce a correct JSON format.
|
|
|
1. Every CSV data record is translated into a JSON object with key-value pairs enclosed in "{}".
|
|
|
2. CSV headers become the keys for each key-value pair.
|
|
|
3. The data values in each column of each CSV record are translated into JSON strings enclosed in double quotes (").
|
|
|
|
|
|
Although this scheme is universal, it could be preferable to translate some data values
|
|
|
into JSON numbers, booleans or the {{{null}}} value instead. However, we first consider
|
|
|
the universal scheme in order to illustrate the simplest application of Parabix methods
|
|
|
to this problem.
|
|
|
|
|
|
## Example
|
|
|
As a simple running example, we use the following CSV input file.
|
... | ... | |