# JSON.jl output undecorated/unquoted string

**URL:** https://discourse.julialang.org/t/json-jl-output-undecorated-unquoted-string/57527
**Category:** General Usage
**Created:** [March 19, 2021, 9:55am UTC](https://discourse.julialang.org/t/json-jl-output-undecorated-unquoted-string/57527 "2021-03-19T09:55:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)
#### Post date: [March 19, 2021, 9:55am UTC](https://discourse.julialang.org/t/json-jl-output-undecorated-unquoted-string/57527/1 "2021-03-19T09:55:25Z")

</div>

Hi,

I have a singleton type `Undefined` which is meant to match JavaScript’s `undefined` primitive. As such, when JSON rendered, this should output as `undefined` instead of the default `"undefined"` (not wrapped in double quotes, similar to how `Nothing` renders as `null` or `Bool` as `true` or `false`).

Specializing `JSON.lower` seems to do the trick partially, but I don’t know what to output in the specialization so that the output is not wrapped in quotes.

For example, this results in `null` because `Base.print` returns `nothing`. How can I return the undecorated/unquoted string or how can this be done?

```julia
JSON.lower(::Undefined) = Base.print("undefined")

```

Thank you

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 19, 2021, 10:10am UTC](https://discourse.julialang.org/t/json-jl-output-undecorated-unquoted-string/57527/2 "2021-03-19T10:10:05Z")

</div>

`undefined` is not valid in JSON so you probably need to come up with some other way of serializing/deserializing it (maybe a dict with a sentinel key).

---

<div class="post-metadata">

### Author: ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)
#### Post date: [March 19, 2021, 10:15am UTC](https://discourse.julialang.org/t/json-jl-output-undecorated-unquoted-string/57527/3 "2021-03-19T10:15:41Z")

</div>

Thanks, yes, valid point.

More correctly phrased, I’m generating a JS configuration object based on Julia data (so generating JS code) using JSON.jl. And I need to customize how some of the Julia objects are JSON serialized as the JS library expects a proper JS `undefined` value.

After more trial and error I seem to have nailed it. Leaving it here for posterity:

```julia
JSON.show_json(io::JSON.Writer.StructuralContext, context::JSON.Serializations.CommonSerialization, x::Undefined) = Base.print(io, "undefined")

```
