# how to parse json structures?

**URL:** https://forum.kx.com/t/how-to-parse-json-structures/9053
**Category:** Community Support
**Tags:** kdb-and-q
**Created:** [September 8, 2014, 6:07am UTC](https://forum.kx.com/t/how-to-parse-json-structures/9053 "2014-09-08T06:07:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Francisco1](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@Francisco1](https://forum.kx.com/u/Francisco1)
#### Post date: [September 8, 2014, 6:07am UTC](https://forum.kx.com/t/how-to-parse-json-structures/9053/1 "2014-09-08T06:07:00Z")

</div>

Hello, I’m using q to access a REST API returning &nbsp;json data structures:

`q)\l json.kq)v:system "curl -k -H \"Authorization: Bearer MyToken\" https://api-fxpractice.oanda.com/v1/accounts" % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 369 100 369 0 0 253 0 0:00:01 0:00:01 --:--:-- 253q)v,"{""\t\"accounts\" : [""\t\t{""\t\t\t\"accountId\" : 1125870,""\t\t\t\"accountName\" : \"Primary\",""\t\t\t\"accountCurrency\" : \"EUR\",""\t\t\t\"marginRate\" : 0.05""\t\t},""\t\t{""\t\t\t\"accountId\" : 9244246,""\t\t\t\"accountName\" : \"Bull\",""\t\t\t\"accountCurrency\" : \"EUR\",""\t\t\t\"marginRate\" : 0.02""\t\t},""\t\t{""\t\t\t\"accountId\" : 6955195,""\t\t\t\"accountName\" : \"Bear\",""\t\t\t\"accountCurrency\" : \"EUR\",""\t\t\t\"marginRate\" : 0.02""\t\t}""\t]","}"`

But I don’t know how to use json.k to parse this data:

`q).j.k vk){=\~("\\"=-1_q,x)<q=x}'length<(0b;,0b;000000000000000b;000b;0000000000000000000000000b;00000000000000000000..(,0b;010000000010000b;000b;0001000000000100000000000b;00010000000000010001000..q.j))`

Please, can you help me?

Cheers

Francisco

---

<div class="post-metadata">

### Author: ![Attila](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Attila](https://forum.kx.com/u/Attila)
#### Post date: [September 8, 2014, 8:03am UTC](https://forum.kx.com/t/how-to-parse-json-structures/9053/2 "2014-09-08T08:03:00Z")

</div>

raze v

&nbsp; Attila

---

<div class="post-metadata">

### Author: ![felix1](https://avatars.discourse-cdn.com/v4/letter/f/3e96dc/32.png) [@felix1](https://forum.kx.com/u/felix1)
#### Post date: [September 8, 2014, 5:26pm UTC](https://forum.kx.com/t/how-to-parse-json-structures/9053/3 "2014-09-08T17:26:00Z")

</div>

The latest kdb has the json parser built in.

Look in the .j namespace for utility functions.

Pe 08.09.2014 08:07, “Francisco” \<frangonve@gmail.com\> a scris:

> Hello, I’m using q to access a REST API returning &nbsp;json data structures:
> 
> `q)\l json.kq)v:system "curl -k -H \"Authorization: Bearer MyToken\" https://api-fxpractice.oanda.com/v1/accounts" % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 369 100 369 0 0 253 0 0:00:01 0:00:01 --:--:-- 253q)v,"{""\t\"accounts\" : [""\t\t{""\t\t\t\"accountId\" : 1125870,""\t\t\t\"accountName\" : \"Primary\",""\t\t\t\"accountCurrency\" : \"EUR\",""\t\t\t\"marginRate\" : 0.05""\t\t},""\t\t{""\t\t\t\"accountId\" : 9244246,""\t\t\t\"accountName\" : \"Bull\",""\t\t\t\"accountCurrency\" : \"EUR\",""\t\t\t\"marginRate\" : 0.02""\t\t},""\t\t{""\t\t\t\"accountId\" : 6955195,""\t\t\t\"accountName\" : \"Bear\",""\t\t\t\"accountCurrency\" : \"EUR\",""\t\t\t\"marginRate\" : 0.02""\t\t}""\t]","}"`
> 
> But I don’t know how to use json.k to parse this data:
> 
> `q).j.k vk){=\~("\\"=-1_q,x)<q=x}'length<(0b;,0b;000000000000000b;000b;0000000000000000000000000b;00000000000000000000..(,0b;010000000010000b;000b;0001000000000100000000000b;00010000000000010001000..q.j))`
> 
> Please, can you help me?
> 
> Cheers
> 
> Francisco
> 
> –  
> Submitted via Google Groups

---

<div class="post-metadata">

### Author: ![josh\_helzer](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@josh\_helzer](https://forum.kx.com/u/josh_helzer)
#### Post date: [September 8, 2014, 8:45pm UTC](https://forum.kx.com/t/how-to-parse-json-structures/9053/4 "2014-09-08T20:45:00Z")

</div>

It does?

KDB+ 3.1 2014.08.22 Copyright (C) 1993-2014 Kx Systems  
l32/ 4()core 15748MB j m5 127.0.1.1 NONEXPIRE&nbsp;

q)key `.j  
q)

---

<div class="post-metadata">

### Author: ![sohagan](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@sohagan](https://forum.kx.com/u/sohagan)
#### Post date: [September 8, 2014, 8:53pm UTC](https://forum.kx.com/t/how-to-parse-json-structures/9053/5 "2014-09-08T20:53:00Z")

</div>

From&nbsp;v3.2 2014.08.22&nbsp;…not sure when the 3.2 free version is being released.

[http://code.kx.com/wiki/Cookbook/Websocket#JSON](http://code.kx.com/wiki/Cookbook/Websocket#JSON)

---

<div class="post-metadata">

### Author: ![Francisco1](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@Francisco1](https://forum.kx.com/u/Francisco1)
#### Post date: [September 10, 2014, 4:19am UTC](https://forum.kx.com/t/how-to-parse-json-structures/9053/6 "2014-09-10T04:19:00Z")

</div>

Thank a lot!

Francisco
