janestreet / ppx_yojson_conv

[@@deriving] plugin to generate Yojson conversion functions
MIT License
58 stars 8 forks source link

What if a json field has name `type` ? #2

Closed impvd closed 3 years ago

impvd commented 3 years ago

I'm trying to create an OCaml type to deserialize a json string:

{
  "pages": 1,
  "data": [
      {
          "SCode": "00006",
          "RDate": "\/Date(1577721600000)\/",
          "TypeCode": "1",
          "Type": "Normal"
      },
      ...
        ],
  "dataUrl": "http://datainterface3.aws.com/pi/ZLCCMX/GetZL"
}

With the OCaml type

type t1 = {
  scode : string;
  rdate : string;
  typecode : string;
  type : string;
}

Well, when I tried to type type in VSCode, I got the error:

image
xclerc commented 3 years ago

Could you double check whether the following (from here) fixes the issue for you?

type t1 = {
  scode : string;
  rdate : string;
  typecode : string;
  type_ : string [@key "type"];
}