Product JSON to CSV
A package that parses commercetools products JSON data to CSV. The products to be parsed can either be read from a .json
file or directly piped in from the product exporter.
Usage
npm install @commercetools/product-json-to-csv --global
CLI
The products to be parsed from JSON to CSV can be passed to this module in one of two ways:
From a pipe
From a file
Pass products through a pipe
Piping products in JSON to be parsed. This ideally works with the commercetools product exporter. In this scenario, the products are parsed directly after export. More information on pipe streams can be found here
Example
Pass products from a file
This module also accepts products to be read from a JSON file. This can be done by specifying the --input
flag
Example
CSV Parser Template
A parser template defines the content of the resulting parsed CSV file, by listing wanted product attribute names as header row. The header column values will be parsed and the resulting CSV file will contain corresponding attribute values of the exported products.
For more information about the template, and how to generate a template for products, see here
Parse without CSV template
Products can however be parsed to CSV without the need to provide a template. In this situation, a zip archive should be passed to the --output
flag. If no template file is passed in, one CSV file will be created for each product type.
Example
Support for different encodings
Parser can save products in a different encoding (than the default utf8
) using --encoding "encodingName"
parameter. Supported encodings are listed here in the iconv-lite
module github page.
Example
JS
For more direct usage, it is possible to use this module directly
Configuration
The constructor accepts four arguments:
apiConfig
(Object):AuthMiddleware
options for authentication on the commercetools platform. (Required. See here)parserConfig
(Object): Internal Parse configurationscategoryBy
(String): Specify which identifier should be used to reference the categories (Options:name
,key
,externalId
andnamedPath
. Default:name
)categoryOrderHintBy
(String): Specify which identifier should be used to reference the categoryOrderHints (Options:name
,key
,externalId
andnamedPath
. Default:name
)delimiter
(String): Delimiter used to separate cells in the output file (Default:;
)fillAllRows
(Boolean): Specify if product attributes like name should be added to each variant row (Default:false
)headerFields
(Array): An array of header fields to be passed to CSV. This headerFields array should contain the required columns of the CSV file(Optional. If omitted, a.zip
file containing one csv file per product type will be created. This is synonymous with the--template
flag in the CLI)language
(String): Default language used when resolving localised attributes (except lenums) and category names (Default:en
)languages
(Array): List of languages which should be exported fromltext/lenum
attributes (Default:["en"]
)encoding
(String): Encoding used when saving products to output stream (Default:utf8
)
multiValueDelimiter
(String): Delimiter used to separate multivalue items in cells in the output file (Default:;
)An optional logger object having four methods (
info
,warn
,error
anddebug
)accessToken
(String): Access token to be used to authenticate requests to API. Requires scope of [view_products
,view_customers
]
Example
Last updated