# How to switch between PrettyContext and CompactContext in JSON package?

**URL:** <https://discourse.julialang.org/t/how-to-switch-between-prettycontext-and-compactcontext-in-json-package/15857>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 4, 2018, 2:26am UTC](https://discourse.julialang.org/t/how-to-switch-between-prettycontext-and-compactcontext-in-json-package/15857 "2018-10-04T02:26:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![YongHee-Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yonghee-kim/32/5965_2.png) [@YongHee-Kim](https://discourse.julialang.org/u/YongHee-Kim)\
**Post date:** [October 4, 2018, 2:26am UTC](https://discourse.julialang.org/t/how-to-switch-between-prettycontext-and-compactcontext-in-json-package/15857/1 "2018-10-04T02:26:29Z")

</div>

I want to write `.json` from DataFrame  
But I want to write some element to be indented, and some are not indented

Here is a minimal example

```julia
using DataFrames
using JSON

function JSON.show_json(io::SC, s::CS, df::DataFrame)
    JSON.begin_array(io)
    for (i, row) in enumerate(eachrow(df))
        JSON.indent(io)
        JSON.begin_object(io)
        for el in row
            if isa(el[2], Array{T} where T <: AbstractString) || isa(el[2], Array{T} where T <: Number)
                JSON.show_key(io, el[1])
                JSON.show_json(io, s, el[2])
            else
                JSON.show_pair(io, s, el)
            end
        end
        JSON.end_object(io)
        i != nrow(df) && JSON.delimit(io)
    end
    JSON.end_array(io)
end

df = DataFrame(element = [1], array = [[100,200]])
JSON.json(df, 2) |> clipboard

```

Which gives me

```json
[
  {
    "element": 1,
    "array": [
      100,
      200
    ]
  }
]

```

What I want it to be is

```json
[
  {
    "element": 1,
    "array": [100,200]
  }
]

```

I’ve figured that I should switch between `PreetyContext` and `CompactContext` in `IO` based on datatype would be an elegant solution, but I don’t know how to implement it.

Thank for your time 😄
