javascript - node.js + API + Json formatting -


i developing rest api using node.js + postgis.in problem in formatting result

consider db below:

name        key         value xxxxxx      population  232 xxxxxx      marginal    24 yyyyyy      population  6372 yyyyyy      marginal    566 

i want output below:

[{ name:xxxx key:population value:232 key:marginal value:24 }, { name:yyyyy key:population value:6372 key:marginal value:566 }] 

i executing following query:

select  name, key, value    map70   key in ('population', 'marginal') group         name, key, value 

but getting output below:

[{ name:xxxx key:population value:232 }, { name:xxxx key:marginal value:24 }, { name:yyyyy key:population value:6372 }, { name:yyyy key:marginal value:566 } ] 

how can have output want..help me solve this.thanks in advance.

you can't have output want.

[{ name:xxxx key:population value:232 key:marginal value:24 }, { name:yyyyy key:population value:6372 key:marginal value:566 }] 

in javascript , hashtables, cannot have multiple keys same name.

what want this:

[{ "name":"xxxx", "population": 232, "marginal": 24 }, { "name":"yyyyy", "population": 6372, "marginal": 566 }] 

or this:

[{ "name":"xxxx", "keys": [  ["population", 232],  ["marginal", 24] ] }, { "name":"yyyyy", "keys": [   ["population", 6372],   ["marginal", 566] ] }] 

to second output, iterate on results. need kind of collection in can save objects need output. each line, check if there object created. if not create one, if there 1 add "keys" array.

obj.keys.push([current.key, current.value]); 

then when finished processing each objects should able dump json out of js object.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -