Skip to content
This repository was archived by the owner on Oct 27, 2023. It is now read-only.

Commit ebffb1d

Browse files
committed
Changed the way I handled the json parse
1 parent 030af2d commit ebffb1d

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
/samples

index.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,29 @@ function processTable(db, dbOut, table) {
5656
}
5757

5858
console.log(`Processing row with key ${row.ID}`);
59-
let toInsert = JSON.parse(row.json);
60-
try {
61-
let tmp = JSON.parse(JSON.parse(toInsert));
62-
if (typeof JSON.parse(tmp) == "object" || Array.isArray(JSON.parse(tmp))) {
63-
toInsert = tmp;
59+
let oldInsert = row.json;
60+
let toInsert = row.json;
61+
62+
while (true) {
63+
try {
64+
const tmp = JSON.parse(toInsert);
65+
if (typeof tmp == "object" || Array.isArray(tmp)) {
66+
break;
67+
} else if (typeof tmp == "string") {
68+
oldInsert = toInsert;
69+
toInsert = tmp;
70+
continue;
71+
} else if (typeof tmp == "number") {
72+
break;
73+
} else if (typeof tmp == "boolean") {
74+
break;
75+
} else {
76+
}
77+
} catch (e) {
78+
// restore last previous string
79+
toInsert = oldInsert;
80+
break;
6481
}
65-
66-
tmp = JSON.parse(tmp);
67-
if (typeof JSON.parse(tmp) == "object" || Array.isArray(JSON.parse(tmp))) {
68-
toInsert = tmp;
69-
}
70-
} catch (e) {
71-
7282
}
7383

7484
stmt.run(row.ID, toInsert);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quick.db-migration-tool",
3-
"version": "1.0.4",
3+
"version": "1.0.6",
44
"description": "",
55
"main": "index.js",
66
"bin": {

0 commit comments

Comments
 (0)