TableCodecs

com.phasmidsoftware.tableparser.json.table.TableCodecs
object TableCodecs

circe codecs for Table[T] (they replace 1.x's TableJsonFormat, which used spray-json).

A Table is represented by a JSON object with a "rows" key (an array of the rows) and, if the table has a header, a "header" key (an array of the column names). For example:

{
 "rows" : [ { "playerA" : "Adam S", "playerB" : "Amy A" } ],
 "header" : [ "playerA", "playerB" ]
}

Use them with import com.phasmidsoftware.tableparser.json.table.TableCodecs.given. The rows need an Encoder (or Decoder): for a case class, derives Codec.AsObject gives both.

NOTE the header and the keys of the rows may differ. The header is the Table's own header: for a table parsed from CSV, that's the column names of the file (e.g. "director_name"). The keys of each row are whatever the row's Encoder writes: for a derived Codec, the field names (e.g. "directorName"). The Decoder reads the rows by their keys, and keeps the header just as it was, so a round trip loses nothing.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Givens

Givens

given tableDecoder: [T : Decoder] => Decoder[Table[T]]

A Decoder for a Table[T]. If there is no "rows" key, the table is empty. If there is no "header" key, the table has no header.

A Decoder for a Table[T]. If there is no "rows" key, the table is empty. If there is no "header" key, the table has no header.

Type parameters

T

the row type, for which there must be a Decoder[T].

Attributes

Returns

a Decoder[Table[T]].

given tableEncoder: [T : Encoder] => Encoder[Table[T]]

An Encoder for a Table[T].

An Encoder for a Table[T].

Type parameters

T

the row type, for which there must be an Encoder[T].

Attributes

Returns

an Encoder[Table[T]].