dasmig-core 1.2.0
Shared random engine, distributions and data tiers for the dasmig generator libraries
Loading...
Searching...
No Matches
sinks.hpp File Reference

Writers for batches: JSON Lines, and CSV flattened from a result's JSON. Both can be given to for_each_batch() as the sink. More...

#include <concepts>
#include <cstddef>
#include <cstdint>
#include <ostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

class  dasmig::core::detail::json_flattener
 
class  dasmig::core::jsonl_writer
 Writes one JSON document per line (JSON Lines / NDJSON). More...
 
class  dasmig::core::csv_writer
 Writes results as CSV, one row each, with columns flattened from their JSON (see flatten_json()). More...
 

Concepts

concept  dasmig::core::json_result
 Whether a result has to_json() returning text.
 

Functions

std::vector< std::pair< std::string, std::string > > dasmig::core::flatten_json (std::string_view json)
 Flatten a JSON document into dotted columns.
 

Detailed Description

Writers for batches: JSON Lines, and CSV flattened from a result's JSON. Both can be given to for_each_batch() as the sink.

Author
Diego Dasso Migotto (diegomigotto at hotmail dot com)

Definition in file sinks.hpp.

Function Documentation

◆ flatten_json()

std::vector< std::pair< std::string, std::string > > dasmig::core::flatten_json ( std::string_view  json)
inline

Flatten a JSON document into dotted columns.

An object's members become parent.child cells, strings are unescaped, numbers and booleans keep their text, null is an empty cell, and an array (or an empty nested object) is one cell holding its JSON text. A document that is not an object gives one cell with an empty name.

Parameters
jsonA complete JSON document.
Returns
The (column, cell) pairs in document order.
Exceptions
std::invalid_argumentIf json is not valid JSON.

Definition at line 280 of file sinks.hpp.