module NdjsonToCsv
Overview
Reshape a file of JSON objects (one per line) into CSV text for the paths you name. Nothing is fetched, nothing is guessed: a path that is not in an object gives an empty cell. The CSV is written by hand, no "csv" library.
Defined in:
ndjson_to_csv.crConstant Summary
-
USAGE =
"usage: ndjson-to-csv file.ndjson [--columns id,name,address.city,tags.0] [--out FILE] [--summary] [--skip-bad]\nOne JSON object per line. A dot goes into an object key, a number goes to an array index. It reshapes text you give; it fetches nothing and flattens only the paths you name.\nMore: https://www.onegtmlab.dev/tool-directory/research-and-scraping/brightdata" -
VERSION =
"1.0.0"
Class Method Summary
-
.cell(value : JSON::Any | Nil) : String
Missing or null is empty.
-
.cli(args : Array(String), stdout : IO, stderr : IO) : Int32
Command line entry.
- .csv(objects : Array(Obj), columns : Array(String)) : String
-
.default_columns(objects : Array(Obj)) : Array(String)
Top level keys in order of first appearance.
-
.lookup(obj : Obj, path : String) : JSON::Any | Nil
Follows a path through one object.
-
.parse(text : String, skip_bad : Bool = false) : Parsed
Reads the text line by line.
-
.parse_columns(text : String) : Array(String)
Comma list of paths.
-
.percent1(part : Int32, whole : Int32) : String
tenths of a percent, rounded half away from zero (counts are never negative)
- .quote(text : String) : String
- .summary(parsed : Parsed, columns : Array(String)) : String
- .table(rows : Array(Array(String))) : String
Class Method Detail
Missing or null is empty. A string is its text. A number or boolean is its JSON text. An object or array is compact JSON text.
Command line entry. Returns the exit code: 0 ok, 1 bad input or file, 2 usage.
Top level keys in order of first appearance.
Follows a path through one object. nil means the path is not there.
Reads the text line by line. Blank lines are skipped (and not counted). A line that is not valid JSON, or is valid JSON but not an object, is bad: an error naming the line number, or counted and skipped with skip_bad.
Comma list of paths. A dot goes into an object key, a whole number goes to an array index. Empty names and empty path parts are errors.
tenths of a percent, rounded half away from zero (counts are never negative)