mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Fixed 'JSON to CSV' handling of complex structures. Closes #637
This commit is contained in:
parent
59c1c45d78
commit
3a9bdc58af
1 changed files with 2 additions and 1 deletions
|
@ -113,11 +113,12 @@ class JSONToCSV extends Operation {
|
||||||
*/
|
*/
|
||||||
escapeCellContents(data) {
|
escapeCellContents(data) {
|
||||||
if (typeof data === "number") data = data.toString();
|
if (typeof data === "number") data = data.toString();
|
||||||
|
if (typeof data !== "string") data = JSON.stringify(data);
|
||||||
|
|
||||||
// Double quotes should be doubled up
|
// Double quotes should be doubled up
|
||||||
data = data.replace(/"/g, '""');
|
data = data.replace(/"/g, '""');
|
||||||
|
|
||||||
// If the cell contains a cell or row delimiter or a double quote, it mut be enclosed in double quotes
|
// If the cell contains a cell or row delimiter or a double quote, it must be enclosed in double quotes
|
||||||
if (
|
if (
|
||||||
data.indexOf(this.cellDelim) >= 0 ||
|
data.indexOf(this.cellDelim) >= 0 ||
|
||||||
data.indexOf(this.rowDelim) >= 0 ||
|
data.indexOf(this.rowDelim) >= 0 ||
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue