2

What would be the best way to parse the "result" of a JSON string in q and build a table out of its structure?

for example, if returned a json order book:

{
  "success":true,
  "message":"",
  "result":{
    "buy":[
      {"Quantity":19999,"Rate":0.73},
      {"Quantity":138877,"Rate":0.72}
    ],
    "sell":[
      {"Quantity":1999,"Rate":0.74},
      {"Quantity":7756,"Rate":0.75}
    ]
  }
}

what is a function that would convert this to:

x        Quantity  Rate
"buy"    19999     0.73
"buy"    138877    0.72
"sell"   1999      0.74
"sell"   7756      0.75

and work on arbitrary levels of nesting in the JSON?

Alexander Belopolsky
  • 2,228
  • 10
  • 26
nightTrevors
  • 639
  • 4
  • 11
  • 24

1 Answers1

3

Have you tried Arthur's implementation?

http://code.kx.com/q/cookbook/websockets/#json

Pretty straightforward.

q)\l json.k // get it from http://kx.com/q/e/json.k
q) // create some table t
q) .j.j t
q) .j.k .j.j t // recreate the json
Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Manish Patel
  • 4,411
  • 4
  • 25
  • 48