Download the PHP package keboola/csvmap without Composer
On this page you can find all versions of the php package keboola/csvmap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package csvmap
CsvMap
Installation
Usage
For example, map key key.nested
of each $data
array item, to CSV column mappedKey
.
Mapping
- The mapping is an array.
- The
key
corresponds to the one root/nested key in the source data. Default delimiter is.
, eg.key
,key.nested
. - The
value
is the mapping configuration for the given key. It isstring
(shorthand notation) orarray
.- There are 3 types of the mapping, defined by the
type
key: type
(optional),column
by default.column
will store the value from its key into a CSV columnuser
will look into an array in the second argument of the parse function and fill a CSV column with its valuetable
will create a "child" CSV and link through a primary key or a hash, if no primary key is defined
- There are 3 types of the mapping, defined by the
Column mapping
mapping
: Required, must containdestination
:destination
: Target column in the output CSV fileprimaryKey
: Optional, boolean. If set to true, the column will be included in the primary key
forceType
: Optional, if a value is not scalar, it'll be JSON encoded
Shorthand notation
- If the
value
is thestring
, then it is a shorthand notation for thecolumn
mapping. - The string value corresponds to
mapping.destination
.
Example shorthand notation:
... is equal to
Examples
Four different column
mappings.
User mapping
Same as column
, except the key of the object is not searched for in the parsed data, but in an array passed to the parser to inject user data
Table mapping
destination
: Required, a target CSV file nametableMapping
: Required, mapping of all child table's columns- Sub-mapping has the same structure as the root
$mapping
.
- Sub-mapping has the same structure as the root
parentKey
: Optional, can be used to set the parent/child link as a primary key in the child or override the link's column name in the childprimaryKey
: boolean, same as incolumn
destination
: Name of the link column (if not used, name of the parent table ._pk
is used by default)disable
: boolean, if set to non-false value, the parent key in the child table, as well as the column in the parent will not be saved
Note:
If the destination
is the same as the current parsed 'type' (destination of the parent),
parentKey.disable
must be true to preserve consistency of structure of the child and parent.
Map scalar items to a separated CSV
- Table mapping is useful when you need to map array of the objects to separate CSV tables.
- But sometimes you need to map an array of the scalar (not object) values, for example a list of tags.
- In this case, you can use an empty key in
tableMapping
to map a scalar value.
For example, we have this data:
Example mapping:
Results:
root.csv
:
tags.csv
:
Examples
Mixed column
and table
mappings.
License
MIT licensed, see LICENSE file.
All versions of csvmap with dependencies
keboola/php-csvtable Version ^2.2
keboola/csv Version ^4.0
php Version ^8.1
ext-json Version *