# Ppx\_deriving\_yojson: Error in the Toplevel

**URL:** <https://discuss.ocaml.org/t/ppx-deriving-yojson-error-in-the-toplevel/4471>\
**Category:** Learning\
**Tags:** yojson, ppx\_deriving, ppx\_deriving\_yojson\
**Created:** [October 1, 2019, 4:12pm UTC](https://discuss.ocaml.org/t/ppx-deriving-yojson-error-in-the-toplevel/4471 "2019-10-01T16:12:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luc\_ML](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/luc_ml/32/1671_2.png) [@Luc\_ML](https://discuss.ocaml.org/u/Luc_ML)\
**Post date:** [October 1, 2019, 4:12pm UTC](https://discuss.ocaml.org/t/ppx-deriving-yojson-error-in-the-toplevel/4471/1 "2019-10-01T16:12:58Z")

</div>

I get the following error when playing in the Toplevel (Emacs) with ppx\_deriving\_yojson (Yojson alone works well):

```auto
#require "yojson";;
#require "ppx_deriving_yojson";;

type foo = { bar : string; } [@@deriving yojson]

Error: Reference to undefined global `Ppx_deriving_yojson_runtime'

```

I’ve read:  
[https://github.com/ocaml-ppx/ppx\_deriving\_yojson](https://github.com/ocaml-ppx/ppx_deriving_yojson)  
[Add ppx\_deriving.runtime to requires in META (#47)](https://github.com/ocaml-ppx/ppx_deriving_yojson/commit/75dfb2ddf012daaa40ce794f0cbe3b08b7d0aea3)

and also the following that explains ppx\_deriving\_yojson.runtime package must be added.  
[Error: Required module `Ppx\_deriving\_yojson\_runtime' is unavailable](https://discuss.ocaml.org/t/error-required-module-ppx-deriving-yojson-runtime-is-unavailable/1229)

So I tried to load this runtime package with the following directive:

```auto
#require "ppx_deriving_json.runtime";; 
(* no visible effect added path or loaded module *)

```

and I still have the same error.

Can you give a hint about what is wrong?  
Thanks.

EDIT  
I confirm I can generate the yojson helpers functions from the ocaml CLI:

```auto
$ ocaml

# #require "yojson";;
# #require "ppx_deriving_yojson";;
# type foo = { bar : string; } [@@deriving yojson]
type foo = { bar : string; }
val foo_to_yojson : foo -> Yojson.Safe.t = <fun>
val foo_of_yojson : Yojson.Safe.t -> foo Ppx_deriving_yojson_runtime.error_or =
  <fun>
val _ : Yojson.Safe.t -> foo Ppx_deriving_yojson_runtime.error_or = <fun>

```

but not from the Toplevel within Emacs.  
So it looks like there is no problem with ocaml and ppx\_deriving\_yojson but more with the Emacs Toplevel.  
Any idea ?
