Comments (12)
Just wrap the result in VALUE()
https://support.google.com/docs/answer/3094220?hl=en
from importjson.
Hi,
am new to git but I paste here what I added into my gs. May need further testing, but it may help you.
Keep in mind that parseInt and parseFloat methods return a number even if only the beginning of the given string was a number. (e.g. parseInt("1.2.1") returns 1, but should not be converted, since it's more of a version number)Added to the transform function:
if (hasOption_(options, "parseNumbers")) {
var num = filterFloat(data[row][column]);
if (!isNaN(num)) {
data[row][column] = num;
}
}New function:
function filterFloat(value) {
if(/^(-|+)?([0-9]+(.[0-9]+)?|Infinity)$/.test(value)) {
return Number(value);
}
return NaN;
}
There is an error in the Regex that makes the script crash. You have to escape the first "+" character.
Here is the corrected version :
if (hasOption_(options, "parseNumbers")) {
var num = filterFloat(data[row][column]);
if (!isNaN(num)) {
data[row][column] = num;
}
}
function filterFloat(value) {
if(/^(-|\+)?([0-9]+(.[0-9]+)?|Infinity)$/.test(value)) {
return Number(value);
}
return NaN;
}
from importjson.
@gaia Is a nice workaround, just separate the query for the numeric column, use VALUE using array forumulas (=ArrayFormula(VALUE(ImportJSON(... ,"/mynumbers",...
).
from importjson.
This issue stems from the "noTruncate" option in the "defaultTransform_" function. If you don't have the noTruncate option added, the value/boolean will be transformed into a string and sliced to max 256 characters. Why do that by default???
Something like this could solve it for numbers & boolean:
if (!hasOption_(options, "noTruncate") && data[row][column]) {
if ((typeof data[row][column]) === 'number' || (typeof data[row][column]) === 'boolean') {
data[row][column] = data[row][column];
} else {
data[row][column] = data[row][column].toString().substr(0, 256);
}
}
from importjson.
Hi,
am new to git but I paste here what I added into my gs. May need further testing, but it may help you.
Keep in mind that parseInt and parseFloat methods return a number even if only the beginning of the given string was a number. (e.g. parseInt("1.2.1") returns 1, but should not be converted, since it's more of a version number)
Added to the transform function:
if (hasOption_(options, "parseNumbers")) {
var num = filterFloat(data[row][column]);
if (!isNaN(num)) {
data[row][column] = num;
}
}
New function:
function filterFloat(value) {
if(/^(-|+)?([0-9]+(.[0-9]+)?|Infinity)$/.test(value)) {
return Number(value);
}
return NaN;
}
from importjson.
@athace Looks good to me. (edit: Google Script doesn't like the regex. 😦)
Though most of the time people are going to want numeric values to be numeric, so make parsing them default behavior, with an option noParseNumbers
to disable it.
from importjson.
Hi, i'm currently facing this issue : my json numeric values are rendered as string instead of numbers.
So, what option should i add the the function call please ?
Same question for dates in YYYY-MM-DD format please ?
That would be really great 🥇
from importjson.
I guess i have to deal with the
from importjson.
@param {parseOptions}
from importjson.
Hi, just to mention that since today, the patch does not work anymore. I had to come back to original non-patched code.
I only get text cells now...but the spreadsheet is loading the right way.
from importjson.
By the way, is this project still maintained please ?
from importjson.
I get a lot of use out of this function, but still run into problems with numbers coming across as strings, not numbers. I've tried inserting the above suggestions into my script, but the data still comes across as a string. I even set up a conditional format on the cells to highlight the ones that were not numbers and it's easy to see that in the same column, 0's are treated as numbers, but any number is treated as a string.
Wondering if anyone has come up with a better solution to this problem?
from importjson.
Related Issues (20)
- How to trigger ImportJSON with a script HOT 1
- ImportJSON & TriggerAutoRefresh Errors
- Function does not compile; Exception: Attribute provided with no value: url HOT 2
- Import JSON stops working! HOT 10
- ImportJSON "Loading..." Issue HOT 9
- Need help in changing item in an array
- How to use "allHeaders" option but only return row 1 (ie 2nd row) HOT 1
- How to add timer? HOT 2
- How to add Api Key header HOT 1
- Extract information from NSE website to Google sheet/ Excel spreadsheet
- Syntax for ImportJSONViaPost
- Read list of URLs from cell range HOT 1
- ERROR Attribute provided with no value: url
- How can I get this value? HOT 1
- Any way to import multiple URLs
- returned code 404 (line 220)
- Only outputting object Object Array
- Flatten JSON not create new rows
- Error message after initial loading...
- #ERROR! SyntaxError: Unexpected end of JSON input (Line 221)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from importjson.