# `RustyJson.OrderedObject`
[🔗](https://github.com/jeffhuen/rustyjson/blob/v0.3.9/lib/ordered_object.ex#L1)

An ordered JSON object that preserves key insertion order.

A wrapper around a keyword list (that supports non-atom keys) allowing for
proper protocol implementations.

This struct is used when decoding JSON with `objects: :ordered_objects` option.
It preserves the original order of keys as they appeared in the JSON input.

Implements the `Access` behaviour and `Enumerable` protocol with
complexity similar to keywords/lists.

## Decoding

    iex> RustyJson.decode!(~s({"b":2,"a":1}), objects: :ordered_objects)
    %RustyJson.OrderedObject{values: [{"b", 2}, {"a", 1}]}

## Encoding

When encoded back to JSON, the original key order is preserved:

    iex> obj = %RustyJson.OrderedObject{values: [{"b", 2}, {"a", 1}]}
    iex> RustyJson.encode!(obj)
    ~s({"b":2,"a":1})

## Access

    iex> obj = RustyJson.OrderedObject.new([{"x", 1}, {"y", 2}])
    iex> obj["x"]
    1

# `t`

```elixir
@type t() :: %RustyJson.OrderedObject{values: [{String.Chars.t(), term()}]}
```

# `new`

```elixir
@spec new([{String.Chars.t(), term()}]) :: t()
```

Creates a new OrderedObject from a list of key-value tuples.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
