Installations
npm install export-from-json
Developer Guide
Typescript
No
Module System
ESM
Node Version
16.20.0
NPM Version
8.19.4
Score
99.1
Supply Chain
99.6
Quality
77
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Languages
TypeScript (87.36%)
HTML (10.33%)
JavaScript (2.32%)
Developer
Download Statistics
Total Downloads
4,967,748
Last Day
4,050
Last Week
34,644
Last Month
175,666
Last Year
2,137,189
GitHub Statistics
175 Stars
576 Commits
32 Forks
5 Watching
1 Branches
6 Contributors
Bundle Size
6.81 kB
Minified
2.40 kB
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
4,967,748
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Export From JSON
Installation
1yarn add export-from-json
or
1npm i --save export-from-json
or
1pnpm i --save export-from-json
Usage
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.
In module system
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 })
In browser
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>
In Node.js server
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')
Types
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 , |
Tips
- You can reference these exported types through a mounted static field
types
, e.g.
1exportFromJSON({ data: jsonData, fileName: 'data', exportType: exportFromJSON.types.csv })
- You can transform the data before exporting by
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
SAST tool is run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Info: all commits (30) are checked with a SAST tool
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:28
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:29
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Info: no jobLevel write permissions found
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
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
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/zheeeng/export-from-json/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/zheeeng/export-from-json/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/zheeeng/export-from-json/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/zheeeng/export-from-json/codeql-analysis.yml/main?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
6.5
/10
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 MoreOther packages similar to 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