Как конвертировать json в csv

от admin

json-2-csv

This node module will convert an array of JSON documents to a CSV string. Column headings will be automatically generated based on the keys of the JSON documents. Nested documents will have a ‘.’ appended between the keys.

It is also capable of converting CSV of the same form back into the original array of JSON documents. The columns headings will be used as the JSON document keys. All lines must have the same exact number of CSV values.

Installation

Upgrading?

Upgrading to v3 from v2? Check out the upgrade guide.

Usage

Looking for examples? Check out the Wiki: json-2-csv Wiki

converter.json2csv(array, callback, options)
  • array — An array of JSON documents to be converted to CSV.
  • callback — A function of the form function (err, csv) ;
    • This function will receive any errors and/or the string of CSV generated.
    • checkSchemaDifferences — Boolean — Should all documents have the same schema?
      • Default: false
      • Note: An error will be thrown if some documents have differing schemas when this is set to true .
      • field — String — Field Delimiter.
        • Default: ,
        • Default: «
        • Default: \n
        • Default: none
        • Default: []
        • Note: When used with unwindArrays , arrays present at excluded key paths will not be unwound.
        • [‘specifications.features’, ‘specifications.mileage’]
        • [‘specifications’]
        • Default: These will be auto-detected from your data by default.
        • Keys can either be specified as a String representing the key path that should be converted, or as an Object with the field property specifying the path. When specifying keys as an Object, you can also optionally specify a title which will be used for that column in the header. The list specified can contain a combination of Objects and Strings.
          • [ ‘key1’, ‘key2’, . ]
          • [ < field: 'key1', title: 'Key 1' >, < field: 'key2' >, ‘key3’, . ]
          • Default: A built-in method is used to parse out a variety of different value types to well-known formats.
          • Note: Using this option may override other options, including useDateIso8601Format and useLocaleFormat .
          • Default: true
          • Default: false
          • Default: false
          • Default: false
          • Default: false
          • Note: If selected, values will be converted using toISOString() rather than toString() or toLocaleString() depending on the other options provided.
          • Default: false
          • Note: If selected, values will be converted using toLocaleString() rather than toString()
          • Default: false
          • Default: false
          Promisified Version: converter.json2csvAsync(array, options)

          Available in version 2.2.0 , this functionality makes use of promises from the bluebird module.

          converter.csv2json(csv, callback, options)

Похожие статьи