snek
snek

Reputation: 2161

Get value of JSON

So, I have looked all over the internet for a solution to this, and have found none.

I am using NodeJS to get the output of a SQLite query and then act on it. The exact JSON returned is

{ 'EXISTS(SELECT 1 FROM data WHERE teamnum=1234 LIMIT 1)': 0 }

and the output can be a 1 or a 0. In the example above it is a 0. I want to get that 1 or 0. Any ideas?

Upvotes: 1

Views: 97

Answers (2)

snek
snek

Reputation: 2161

So i just decided to change my SQLite query to make SQLite figure out the logic instead of making node do it.

P.S. The above answer did work for my code.

Upvotes: 0

Nonemoticoner
Nonemoticoner

Reputation: 648

Assuming that you really have that object with data - this will work:

var obj = {'EXISTS(SELECT 1 FROM data WHERE teamnum=1234 LIMIT 1)':0};
var ans = parseInt(JSON.stringify(obj).match(/:(.*?)}/)[1]);

Where ans will be equal to 0.

Upvotes: 1

Related Questions