Skip to content

Commit 07adcfd

Browse files
fix: handle JSON Objects in parseFromFluxResults (#4733)
1 parent 64f5aef commit 07adcfd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/timeMachine/utils/rawFluxDataTable.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ export const parseFromFluxResults = (
2929
const groupSet = new Set(fluxGroupKeyUnion)
3030
let max = 0
3131

32+
// checks whether the string is valid JSON object or not
33+
const isJsonObject = jsonString => {
34+
try {
35+
const object = JSON.parse(jsonString)
36+
if (object && typeof object === 'object') {
37+
return true
38+
}
39+
} catch {}
40+
41+
return false
42+
}
43+
3244
for (let i = 0; i < tables.length; i++) {
3345
if (values[i] !== currVal || tables[i] !== currTable) {
3446
// sets the boundaries for the chunk based on different yields or tables
@@ -72,7 +84,16 @@ export const parseFromFluxResults = (
7284
) {
7385
columnData = new Date(columnData).toISOString()
7486
}
75-
if (typeof columnData === 'string') {
87+
88+
// (Sahas):
89+
// the columnData can have a comma (,) in two cases
90+
// 1. it's a JSON Object
91+
// 2. It's a string of CSV
92+
if (isJsonObject(columnData)) {
93+
// 1. replace Double quotes \" with Single quotes \' in a json object
94+
// 2. then wrap the JSON object in double quotes
95+
columnData = `"${columnData.replace(/['"]+/g, "'")}"`
96+
} else if (typeof columnData === 'string' && columnData.includes(',')) {
7697
columnData = `"${columnData}"`
7798
}
7899
if (column === 'result') {

0 commit comments

Comments
 (0)