# The `.j` namespace

_JSON serialization_


[.j.j   serialize](#jj-serialize)                [.j.k   deserialize](#jk-deserialize)
[.j.jd  serialize infinity](#jjd-serialize-infinity)


The `.j` [namespace](../basics/namespaces.md) contains functions for converting between JSON and q dictionaries.

> **Warning — The `.j` namespace is reserved for use by KX, as are all single-letter namespaces.**
>
>
> Consider all undocumented functions in the namespace as its private API – and do not use them.
>
Prior to V3.2, JSON parsing was catered for via use of the script [KxSystems/kdb/e/json.k](https://github.com/KxSystems/kdb/blob/master/e/json.k)

## `.j.j` (serialize)
```syntax
.j.j x
```

Where `x` is a K object, returns a string representing it in JSON.

## `.j.jd` (serialize infinity)
```syntax
.j.jd (x;d)
```

Where

- `x` is a K object
- `d` is a dictionary

returns the result of `.j.j` unless ``d[`null0w]`` is 1b, in which case `0w` and `-0w` are mapped to `"null"`.
(Since V3.6 2018.12.06.)
```q
q).j.j -0w 0 1 2 3 0w
"[-inf,0,1,2,3,inf]"
q).j.jd(-0w 0 1 2 3 0w;()!())
"[-inf,0,1,2,3,inf]"
q).j.jd(-0w 0 1 2 3 0w;([null0w:1b]))
"[null,0,1,2,3,null]"
```

## `.j.k` (deserialize)
```syntax
.j.k x
```

Where `x` is a string containing JSON, returns a K object.
```q
q).j.k 0N!.j.j `a`b!(0 1;("hello";"world"))        / dictionary
"{\"a\":[0,1],\"b\":[\"hello\",\"world\"]}"
a| 0       1
b| "hello" "world"
q).j.k 0N!.j.j ([]a:1 2;b:`Greetings`Earthlings)   / table
"[{\"a\":1,\"b\":\"Greetings\"},{\"a\":2,\"b\":\"Earthlings\"}]"
a b
--------------
1 "Greetings"
2 "Earthlings"
```

> **Warning — Note serialization and deserialization to and from JSON may not preserve q datatype**
>
>
If your JSON data is spread over multiple lines, reduce those to a single char vector with [`raze`](raze.md).
```bash
$ cat t1.json
{
   "code" : 3,
   "message" : "This request requires authorization"
}
```
```q
q).j.k raze read0 `:t1.json
code   | 3f
message| "This request requires authorization"
```
