> For the complete documentation index, see [llms.txt](https://til.yulrizka.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.yulrizka.com/analytics/convert-json-perline-to-panads-data-frame.md).

# convert json perline to panads data frame

Sometimes we have a file that contains a json object per line. For example log file in json format

```
{foo: 1, bar: 2}
{foo: 3, bar: 4}
```

if we want to read this in python pandas we need to convert it to

```
[
  {foo: 1, bar: 2},
  {foo: 3, bar: 4}
]
```

easy way to do this is with `jq --slurp`

```
$ cat file.json | jq --slurp . > one_array.json
```

then you can read it in python pandas (notebook) like this

```python
sf = pd.read_json('one_array.json')
```
