# Merging two JSON objects

**URL:** <https://forum.crystal-lang.org/t/merging-two-json-objects/1660>\
**Category:** Help & Support\
**Created:** [January 27, 2020, 11:14pm UTC](https://forum.crystal-lang.org/t/merging-two-json-objects/1660 "2020-01-27T23:14:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spinscale](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/spinscale/32/63_2.png) [@spinscale](https://forum.crystal-lang.org/u/spinscale)\
**Post date:** [January 27, 2020, 11:14pm UTC](https://forum.crystal-lang.org/t/merging-two-json-objects/1660/1 "2020-01-27T23:14:43Z")

</div>

Hey,

I got two JSON objects and would like to merge them together into a single one. Are there any helper methods that I am not seeing or do I just go ahead and do this manually?

Thanks for any pointers!

–Alex

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [January 28, 2020, 1:01am UTC](https://forum.crystal-lang.org/t/merging-two-json-objects/1660/2 "2020-01-28T01:01:34Z")

</div>

Do you want to …

- emit the result of the merge? =\> use the json builder
- access them in a fallback fashion? =\> maybe the `dig` methods might help to have a in flight fallback of any key.
- have a `JSON::Any` value? =\> yeah, manually I think.

---

<div class="post-metadata">

**Author:** ![pynixwang](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/pynixwang/32/310_2.png) [@pynixwang](https://forum.crystal-lang.org/u/pynixwang)\
**Post date:** [February 3, 2020, 3:02am UTC](https://forum.crystal-lang.org/t/merging-two-json-objects/1660/3 "2020-02-03T03:02:30Z")

</div>

a.to\_h.merge(b.to\_h)

---

<div class="post-metadata">

**Author:** ![anykeyh](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/anykeyh/32/726_2.png) [@anykeyh](https://forum.crystal-lang.org/u/anykeyh)\
**Post date:** [February 3, 2020, 6:15am UTC](https://forum.crystal-lang.org/t/merging-two-json-objects/1660/4 "2020-02-03T06:15:26Z")

</div>

You could use [JSON::OnSteroids](https://github.com/anykeyh/json_on_steroids).

Basically it’s mutable JSON structure, allowing you to transform it. The documentation is still in progress but there’s a merge method built-in.

```crystal
new_json = json1.on_steroids.merge!(json2)

new_json.to_json

```
