Viewing to_yojson and of_yojson implementation for types

Hi Team, is there any way to view the implementation of to_json and of_json implementation for a particular type generated by ppx_deriving_yojson and yojson

type person = {
  name : string;
  age : int;
}

[@@deriving yojson]

Now I wanted to see person_to_yojson and person_of_yojson implementation generated by ppx??

1 Like

Add -dsource compiler flag, and run dune --verbose

1 Like

@Kakadu can you please tell me where to add this -dsource flag?

You don’t have to bother with -dsource and the log. Instead you can simply use dune show pp path/to/file.ml. It will display the preprocessed source.

5 Likes

Hello @xxus,

Here is an example of my dune file with ā€˜-dsource’

(executable
 (public_name test)
 (name main)
 (libraries unix fmt cryptokit ppx_yojson_conv_lib yojson)
 (preprocess (pps ppx_yojson_conv)))

(env
 (dev
  (flags (:standard -w +42 -warn-error -32 -warn-error -33 -dsource) ))
 (release
  (ocamlopt_flags (:standard -O3))))

If you’re using VSCode, you can also use Ctrl + Shift + P -> OCaml: Show Preprocessed Document to see the ppx output right in your editor

1 Like

with ocamllsp it’s now also possible to ā€œhoverā€ or get type at point on @@deriving and it will show the generated code.