diff --git a/src/helper.ts b/src/helper.ts index c5b5573..05e6fab 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -134,6 +134,9 @@ function addDataType( case "double": updatedObjectWithDataType[key] = Number(input[key]); break; + case "json": + updatedObjectWithDataType[key] = JSON.parse(input[key]); + break; default: updatedObjectWithDataType[key] = input[key]; } diff --git a/test/index.test.ts b/test/index.test.ts index 5064dff..c3afd4c 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -37,6 +37,7 @@ test("parse to json following ColumnInfo", async () => { { Name: "score4", Type: "int" }, { Name: "rate1", Type: "float" }, { Name: "rate2", Type: "double" }, + { Name: "metadata", Type: "json" }, ], }, Rows: [ @@ -52,6 +53,7 @@ test("parse to json following ColumnInfo", async () => { { VarCharValue: "score4" }, { VarCharValue: "rate1" }, { VarCharValue: "rate2" }, + { VarCharValue: "metadata" }, ], }, { @@ -65,6 +67,12 @@ test("parse to json following ColumnInfo", async () => { { VarCharValue: "104" }, { VarCharValue: "1.01" }, { VarCharValue: "1.02" }, + { + VarCharValue: JSON.stringify({ + key1: "value1", + key2: "value2", + }), + }, ], }, ], @@ -86,6 +94,7 @@ test("parse to json following ColumnInfo", async () => { score4: 104, rate1: 1.01, rate2: 1.02, + metadata: { key1: "value1", key2: "value2" }, }); });