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

Parse numbers from string by default and add 'noParseNumbers' option … #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ImportJSON.gs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* rawHeaders: Don't prettify headers
* noHeaders: Don't include headers, only the data
* debugLocation: Prepend each value with the row & column it belongs in
* noParseNumbers: Don't parse string as number
*
* For example:
*
Expand Down Expand Up @@ -93,6 +94,7 @@ function ImportJSON(url, query, parseOptions) {
* rawHeaders: Don't prettify headers
* noHeaders: Don't include headers, only the data
* debugLocation: Prepend each value with the row & column it belongs in
* noParseNumbers: Don't parse string as number
*
* For example:
*
Expand Down Expand Up @@ -150,6 +152,7 @@ function ImportJSONViaPost(url, payload, fetchOptions, query, parseOptions) {
* rawHeaders: Don't prettify headers
* noHeaders: Don't include headers, only the data
* debugLocation: Prepend each value with the row & column it belongs in
* noParseNumbers: Don't parse string as number
*
* For example:
*
Expand Down Expand Up @@ -477,6 +480,7 @@ function applyXPathRule_(rule, path, options) {
* noTruncate: Don't truncate values
* rawHeaders: Don't prettify headers
* debugLocation: Prepend each value with the row & column it belongs in
* noParseNumbers: Don't parse string as number
*/
function defaultTransform_(data, row, column, options) {
if (data[row][column] == null) {
Expand All @@ -502,6 +506,12 @@ function defaultTransform_(data, row, column, options) {
if (hasOption_(options, "debugLocation")) {
data[row][column] = "[" + row + "," + column + "]" + data[row][column];
}

if (!hasOption_(options, "noParseNumbers")) {
if (!isNaN(Number(data[row][column]))) {
data[row][column] = parseFloat(data[row][column]);
}
}
}

/**
Expand Down