# Pretty printing JSON in JuliaIO/JSON.jl

**URL:** <https://discourse.julialang.org/t/pretty-printing-json-in-juliaio-json-jl/6315>\
**Category:** General Usage\
**Created:** [October 7, 2017, 11:02pm UTC](https://discourse.julialang.org/t/pretty-printing-json-in-juliaio-json-jl/6315 "2017-10-07T23:02:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NickNack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicknack/32/1792_2.png) [@NickNack](https://discourse.julialang.org/u/NickNack)\
**Post date:** [October 7, 2017, 11:02pm UTC](https://discourse.julialang.org/t/pretty-printing-json-in-juliaio-json-jl/6315/1 "2017-10-07T23:02:22Z")

</div>

Doesn’t pretty printing of JSON strings with [JSON.jl](https://github.com/JuliaIO/JSON.jl) work? The README doesn’t explicitly mention pretty printing, but indentation is mentioned all over the code and there are `print` methods with an indentation parameter.

Here’s the sample JSON string from the README page and my attempt at printing it with 4 spaces of indentation:

```julia
julia> s = "{\"a_number\" : 5.0, \"an_array\" : [\"string\", 9]}"
"{\"a_number\" : 5.0, \"an_array\" : [\"string\", 9]}"

julia> JSON.print(s,4)
"{\"a_number\" : 5.0, \"an_array\" : [\"string\", 9]}"

```

And here’s another sample if someone wants to test something with a bit of nesting.

```julia
ss = "{\"breakpoints\":{\"1\":{\"year\":2015,\"value\":33.3,\"unit\":1},\"2\":{\"year\":2040,\"value\":40,\"unit\":1},\"3\":{\"year\":2050,\"value\":40,\"unit\":1},\"4\":{\"year\":2100,\"value\":0,\"unit\":2}},\"parameter\":2.2}"

```

---

<div class="post-metadata">

**Author:** ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)\
**Post date:** [October 7, 2017, 11:11pm UTC](https://discourse.julialang.org/t/pretty-printing-json-in-juliaio-json-jl/6315/2 "2017-10-07T23:11:52Z")

</div>

You need to parse it first

```julia
julia> JSON.print(JSON.parse(s), 4)
{
    "an_array": [
        "string",
        9
    ],
    "a_number": 5.0
}

```

```julia
julia> JSON.print(JSON.parse(ss), 4)
{
    "parameter": 2.2,
    "breakpoints": {
        "4": {
            "year": 2100,
            "unit": 2,
            "value": 0
        },
        "1": {
            "year": 2015,
            "unit": 1,
            "value": 33.3
        },
        "2": {
            "year": 2040,
            "unit": 1,
            "value": 40
        },
        "3": {
            "year": 2050,
            "unit": 1,
            "value": 40
        }
    }
}

```
