# \[ANN\] Yojson 2.0.0

**URL:** <https://discuss.ocaml.org/t/ann-yojson-2-0-0/10003>\
**Category:** Ecosystem\
**Tags:** json, yojson, announce\
**Created:** [June 10, 2022, 8:12am UTC](https://discuss.ocaml.org/t/ann-yojson-2-0-0/10003 "2022-06-10T08:12:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonidas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/leonidas/32/4039_2.png) [@Leonidas](https://discuss.ocaml.org/u/Leonidas)\
**Post date:** [June 10, 2022, 8:12am UTC](https://discuss.ocaml.org/t/ann-yojson-2-0-0/10003/1 "2022-06-10T08:12:54Z")

</div>

Hello fellow Camel-wranglers,

This Friday, it is my pleasure to announce the release of Yojson 2.0.0. You can get it [in your local OPAM repository](https://opam.ocaml.org/packages/yojson/).

Key highlights include:

- Fewer dependencies: Given Yojson is a common dependency we cut down on its dependencies so you have to install less and have less transitive dependencies
- `Seq` interface: Since OCaml 4.14 deprecates `Stream` and 5.0 removes it, this was a good time to change to this interface
- `Buffer` interface: coming along with #1, we changed Yojson to use `Buffer` wherever it was using `Biniou` types before

Thanks to everybody involved in this release!

If Yojson sounds like an interesting project for you to contribute, [join us](https://github.com/ocaml-community/yojson).

Full changelog follows:

## 2.0.0

_2022-06-02_

### Removed

- Removed dependency on easy-format and removed `pretty_format` from  
`Yojson`, `Yojson.Basic`, `Yojson.Safe` and `Yojson.Raw`. (@c-cube, #90)
- Removed dependency on `biniou`, simplifying the chain of dependencies. This  
changes some APIs:
  - `Bi_outbuf.t` in signatures is replaced with `Buffer.t`
  - `to_outbuf` becomes `to_buffer` and `stream_to_outbuf` becomes  
`stream_to_buffer`  
(@Leonidas, #74, and @gasche, #132)

- Removed `yojson-biniou` library
- Removed deprecated `json` type aliasing type `t` which has been available  
since 1.6.0 (@Leonidas, #100).
- Removed `json_max` type (@Leonidas, #103)
- Removed constraint that the “root” value being rendered (via either  
`pretty_print` or `to_string`) must be an object or array. (@cemerick, #121)
- Removed `validate_json` as it only made sense if the type was called `json`.  
(@Leonidas, #137)

### Add

- Add an opam package `yojson-bench` to deal with benchmarks dependency  
(@tmcgilchrist, #117)
- Add a benchmark to judge the respective performance of providing a buffer vs  
letting Yojson create an internal (#134, @Leonidas)
- Add an optional `suf` keyword argument was added to functions that write  
serialized JSON, thus allowing NDJSON output. Most functions default to not  
adding any suffix except for `to_file` (#124, @panglesd) and functions  
writing sequences of values where the default is `\n` (#135,  
@Leonidas)

### Change

- The `stream_from_*` and `stream_to_*` functions now use a `Seq.t` instead of a  
`Stream.t`, and they are renamed into `seq_from_*` and `seq_to_*` (@gasche, #131).

### Fix

- Avoid copying unnecessarily large amounts of strings when parsing (#85, #108,  
@Leonidas)
- Fix `stream_to_file` (#133, @tcoopman and @gasche)

---

<div class="post-metadata">

**Author:** ![VPhantom](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vphantom/32/1396_2.png) [@VPhantom](https://discuss.ocaml.org/u/VPhantom)\
**Post date:** [June 10, 2022, 11:22am UTC](https://discuss.ocaml.org/t/ann-yojson-2-0-0/10003/2 "2022-06-10T11:22:49Z")

</div>

Yay!! That was a long time coming. Thank you! 😃

---

<div class="post-metadata">

**Author:** ![orbitz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/orbitz/32/110_2.png) [@orbitz](https://discuss.ocaml.org/u/orbitz)\
**Post date:** [July 8, 2023, 6:23pm UTC](https://discuss.ocaml.org/t/ann-yojson-2-0-0/10003/3 "2023-07-08T18:23:35Z")

</div>

Hello,

I’m curious if anyone has seen a serious performance regression starting in Yojson 2.0.0 under js\_of\_ocaml. I am seeing a huge performance difference in decoding JSON. In my case I’m decoding lists around 1000 elements long of objects and those just never finish decoding in any reasonable timescale. As comparison, using Yojson 1.7.0 that list takes around 1 second.

Sorry, I have not tracked this down any deeper yet, I figured this would be something someone else has run into before going too deep.

---

<div class="post-metadata">

**Author:** ![Leonidas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/leonidas/32/4039_2.png) [@Leonidas](https://discuss.ocaml.org/u/Leonidas)\
**Post date:** [July 13, 2023, 9:38am UTC](https://discuss.ocaml.org/t/ann-yojson-2-0-0/10003/4 "2023-07-13T09:38:19Z")

</div>

I haven’t observed any but I also didn’t test under JSOO. The only relevant thing I could think of is the change from `easy-format` to `Format` but I would think this only affects encoding JSON, not decoding it.

In general there haven’t been that many internal changes, 2.0.0 was mostly about removing older stuff that is breaking the API but not a rework like the 2.0 might suggest.

---

<div class="post-metadata">

**Author:** ![orbitz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/orbitz/32/110_2.png) [@orbitz](https://discuss.ocaml.org/u/orbitz)\
**Post date:** [July 16, 2023, 11:41am UTC](https://discuss.ocaml.org/t/ann-yojson-2-0-0/10003/5 "2023-07-16T11:41:25Z")

</div>

Strange. When I pause execution in the browser, almost always it’s in `caml_convert_bytes_to_array`
