Reputation: 546
For good reasons not worth explaining, I would like to use alasql to pull a numeric value from a nested json object. According to the docs it seems like this should work:
const data = {a:{b:42}};
const answer = alasql('select a->b from ?',[data])
But that gives me back this nonsense rather than the answer of 42 that I want:
[ { 'a->b': undefined } ]
I also tried this (where the input data is not an array):
const data = {a:{b:42}};
const response = alasql('select a->b from ?',data);
But that gives me this unhelpful error: Data source number 0 in undefined
This works and returns 42 a I would expect:
alasql('select value {a:{b:42}}->a->b')
And this also works:
const data = {a:{b:42}};
const response = alasql('select value '+JSON.stringify(data)+'->a->b')
But it seems crazy to shove the data in as a stringified object.
Is there a way to get alasql to just treat my object like an object and let me take it apart with -> operator?
Upvotes: 3
Views: 770