# \[JSON3\] Order of the fields

**URL:** <https://discourse.julialang.org/t/json3-order-of-the-fields/75331>\
**Category:** Data\
**Created:** [January 27, 2022, 11:24pm UTC](https://discourse.julialang.org/t/json3-order-of-the-fields/75331 "2022-01-27T23:24:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![whatsthecraic](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@whatsthecraic](https://discourse.julialang.org/u/whatsthecraic)\
**Post date:** [January 27, 2022, 11:24pm UTC](https://discourse.julialang.org/t/json3-order-of-the-fields/75331/1 "2022-01-27T23:24:29Z")

</div>

Hi, is there a way to specify the order of the fields when writing with JSON3. E.g. in julia 1.7, ` JSON3.pretty(Dict("a" => 1, "b" => 2, "c" => 3, "d" => 4))` yields

```julia
{
   "c": 3,
   "b": 2,
   "a": 1,
   "d": 4
}

```

while the output I’m looking is:

```julia
{
   "a": 1,
   "b": 2,
   "c": 3,
   "d": 4
}

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 28, 2022, 12:41am UTC](https://discourse.julialang.org/t/json3-order-of-the-fields/75331/2 "2022-01-28T00:41:41Z")

</div>

Just a guess, it prints what you want if you use an `OrderedDict` from `DataStructures` instead of the plain `Dict`?

(I think I’ve done that before… It was with TOML)

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [January 28, 2022, 3:19am UTC](https://discourse.julialang.org/t/json3-order-of-the-fields/75331/3 "2022-01-28T03:19:12Z")

</div>

You could also use a NamedTuple, like `JSON3.pretty((a=1, b=2, c=3, d=4))`

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [January 28, 2022, 3:31am UTC](https://discourse.julialang.org/t/json3-order-of-the-fields/75331/4 "2022-01-28T03:31:33Z")

</div>

keep in mind JSON spec is order-less, while it might be pleasing to human eyes, make sure don’t depend on the order at any stage of your pipeline (yes, it has happened to me that someone wrote a order-dependent JSON parser in C++ and took 10 hours to debug)
