Gathering detailed insights and metrics for export-from-json
Gathering detailed insights and metrics for export-from-json
Gathering detailed insights and metrics for export-from-json
Gathering detailed insights and metrics for export-from-json
vue-json-excel
Download your JSON as an excel or CSV file directly from the browser
export-to-csv
Easily create CSV data from json collection
vue-json-excel3
Download your JSON as an excel or CSV file directly from the browser
export-to-csv-fix-source-map
Easily create CSV data from json collection
npm install export-from-json
Typescript
Module System
Node Version
NPM Version
99.1
Supply Chain
99.6
Quality
77
Maintenance
100
Vulnerability
100
License
TypeScript (87.36%)
HTML (10.33%)
JavaScript (2.32%)
Total Downloads
4,967,748
Last Day
4,050
Last Week
34,644
Last Month
175,666
Last Year
2,137,189
175 Stars
576 Commits
32 Forks
5 Watching
1 Branches
6 Contributors
Minified
Minified + Gzipped
Latest Version
1.7.4
Package Id
export-from-json@1.7.4
Unpacked Size
82.22 kB
Size
17.53 kB
File Count
30
NPM Version
8.19.4
Node Version
16.20.0
Publised On
28 Dec 2023
Cumulative downloads
Total Downloads
Last day
-47.9%
4,050
Compared to previous day
Last week
-20.7%
34,644
Compared to previous week
Last month
2.4%
175,666
Compared to previous month
Last year
56.3%
2,137,189
Compared to previous year
1yarn add export-from-json
or
1npm i --save export-from-json
or
1pnpm i --save export-from-json
exportFromJSON
supports CommonJS, EcmaScript Module, UMD importing.
exportFromJSON
receives the option as the Types Chapter demonstrated, and it uses a front-end downloader as the default processor. In browser environment, there is a content size limitation on the default processor, consider using the server side solution.
1import exportFromJSON from 'export-from-json' 2 3const data = [{ foo: 'foo'}, { bar: 'bar' }] 4const fileName = 'download' 5const exportType = exportFromJSON.types.csv 6 7exportFromJSON({ data, fileName, exportType })
Check the codepen example
1<script src="https://unpkg.com/export-from-json/dist/umd/index.min.js"></script> 2<script> 3 const data = [{ foo: 'foo'}, { bar: 'bar' }] 4 const fileName = 'download' 5 const exportType = 'csv' 6 7 window.exportFromJSON({ data, fileName, exportType }) 8</script>
exportFromJSON
returns what the option processor
returns, we can use it on server side for providing a converting/downloading service:
1const http = require('http') 2const exportFromJSON = require('export-from-json') 3 4http.createServer(function (request, response){ 5 // exportFromJSON actually supports passing JSON as the data option. It's very common that reading it from http request directly. 6 const data = '[{"foo":"foo"},{"bar":"bar"}]' 7 const fileName = 'download' 8 const exportType = 'txt' 9 10 const result = exportFromJSON({ 11 data, 12 fileName, 13 exportType, 14 processor (content, type, fileName) { 15 switch (type) { 16 case 'txt': 17 response.setHeader('Content-Type', 'text/plain') 18 break 19 case 'css': 20 response.setHeader('Content-Type', 'text/css') 21 break 22 case 'html': 23 response.setHeader('Content-Type', 'text/html') 24 break 25 case 'json': 26 response.setHeader('Content-Type', 'text/plain') 27 break 28 case 'csv': 29 response.setHeader('Content-Type', 'text/csv') 30 break 31 case 'xls': 32 response.setHeader('Content-Type', 'application/vnd.ms-excel') 33 break 34 } 35 response.setHeader('Content-disposition', 'attachment;filename=' + fileName) 36 return content 37 } 38 }) 39 40 response.write(result) 41 response.end() 42}).listen(8080, '127.0.0.1')
Note: JSON
refers to a parsable JSON string or a serializable JavaScript object.
Option name | Required | Type | Description |
---|---|---|---|
data | true | Array<JSON> , JSON or string | If the exportType is 'json', data can be any parsable JSON. If the exportType is 'csv' or 'xls', data can only be an array of parsable JSON. If the exportType is 'txt', 'css', 'html', the data must be a string type. |
fileName | false | string | filename without extension, default to 'download' |
extension | false | string | filename extension, by default it takes the exportType |
fileNameFormatter | false | (name: string) => string | filename formatter, by default the file name will be formatted to snake case |
fields | false | string[] or field name mapper type Record<string, string> | fields filter, also supports mapper field name by passing an name mapper, e.g. { 'bar': 'baz' }, default to undefined |
exportType | false | Enum ExportType | 'txt'(default), 'css', 'html', 'json', 'csv', 'xls', 'xml' |
processor | false | (content: string, type: ExportType, fileName: string) => any | default to a front-end downloader |
withBOM | false | boolean | Add BOM(byte order mark) meta to CSV file. BOM is expected by Excel when reading UTF8 CSV file. It is default to false . |
beforeTableEncode | false | (entries: { fieldName: string, fieldValues: string[] }[]) => { fieldName: string, fieldValues: string[] }[] | Given a chance to altering table entries, only works for CSV and XLS file, by default no altering. |
delimiter | false | ',' | ';' | Specify CSV raw data's delimiter between values. It is default to , |
types
, e.g.1exportFromJSON({ data: jsonData, fileName: 'data', exportType: exportFromJSON.types.csv })
beforeTableEncode
, e.g.1exportFromJSON({
2 data: jsonData,
3 fileName: 'data',
4 exportType: exportFromJSON.types.csv,
5 beforeTableEncode: rows => rows.sort((p, c) => p.fieldName.localeCompare(c.fieldName)),
6})
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
2 existing vulnerabilities detected
Details
Reason
8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More