Reputation: 9617
I have in my google sheets cell(A10) json object with price: {"bitcoin":{"usd":45258}}
How do I parse this price number and exctract it to do something?
Like for example in C10 cell I want to write: "=A10['bitcoin']['usd']*B10"
Upvotes: 1
Views: 1989
Reputation: 402
This function may help.
function getData(json, path) {
const obj = JSON.parse(json);
const keys = path.split('.');
let current = obj;
for( key of keys ){
current = current[key];
}
return current;
}
And you can write in C10 like this:
=getData(A10, "bitcoin.usd")*B10
Chain the property names with "."
Here is a sample. Feel free to make a copy and check it.👍
Upvotes: 5