{"action":"created","issue":{"url":"https://api.github.com/repos/whitequark/ppx_deriving_yojson/issues/32","labels_url":"https://api.github.com/repos/whitequark/ppx_deriving_yojson/issues/32/labels{/name}","comments_url":"https://api.github.com/repos/whitequark/ppx_deriving_yojson/issues/32/comments","events_url":"https://api.github.com/repos/whitequark/ppx_deriving_yojson/issues/32/events","html_url":"https://github.com/whitequark/ppx_deriving_yojson/issues/32","id":88753546,"number":32,"title":"Encoding of variants with no args","user":{"login":"zoggy","id":515002,"avatar_url":"https://avatars.githubusercontent.com/u/515002?v=3","gravatar_id":"","url":"https://api.github.com/users/zoggy","html_url":"https://github.com/zoggy","followers_url":"https://api.github.com/users/zoggy/followers","following_url":"https://api.github.com/users/zoggy/following{/other_user}","gists_url":"https://api.github.com/users/zoggy/gists{/gist_id}","starred_url":"https://api.github.com/users/zoggy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoggy/subscriptions","organizations_url":"https://api.github.com/users/zoggy/orgs","repos_url":"https://api.github.com/users/zoggy/repos","events_url":"https://api.github.com/users/zoggy/events{/privacy}","received_events_url":"https://api.github.com/users/zoggy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-06-16T15:03:09Z","updated_at":"2015-12-15T13:50:40Z","closed_at":null,"body":"Hello,\r\n\r\nBy now, variant constructors with no arguments, for example `Foo` in `type t = Foo` are encoded as\r\n`` `List [`String \"Foo\"]``. Would it be possible to encoded these as just `` `String \"Foo\"`` ? (and read them back from the same way, of course).\r\n\r\nThe reason is that it is quite heavy to have to put them in a list. I encouter the problem when wanting to use generated JSON encoder/decoder functions in Ocf wrappers.\r\n"},"comment":{"url":"https://api.github.com/repos/whitequark/ppx_deriving_yojson/issues/comments/164770022","html_url":"https://github.com/whitequark/ppx_deriving_yojson/issues/32#issuecomment-164770022","issue_url":"https://api.github.com/repos/whitequark/ppx_deriving_yojson/issues/32","id":164770022,"user":{"login":"michipili","id":5123318,"avatar_url":"https://avatars.githubusercontent.com/u/5123318?v=3","gravatar_id":"","url":"https://api.github.com/users/michipili","html_url":"https://github.com/michipili","followers_url":"https://api.github.com/users/michipili/followers","following_url":"https://api.github.com/users/michipili/following{/other_user}","gists_url":"https://api.github.com/users/michipili/gists{/gist_id}","starred_url":"https://api.github.com/users/michipili/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michipili/subscriptions","organizations_url":"https://api.github.com/users/michipili/orgs","repos_url":"https://api.github.com/users/michipili/repos","events_url":"https://api.github.com/users/michipili/events{/privacy}","received_events_url":"https://api.github.com/users/michipili/received_events","type":"User","site_admin":false},"created_at":"2015-12-15T13:50:40Z","updated_at":"2015-12-15T13:50:40Z","body":"I think we should consider two cases:\r\n\r\n1. The case where the sum type is an enumeration, that is, consists of a list of constant constructors.\r\n2. The case where the sum type is mixed, that is, has constant constructors and not constant constructors.\r\n\r\nIn my experience with various JSON/HTTP restful APIs, the most common use case of a flat encoding of variants would be the case of enumerations. For me, it would fill the bill to be able to decorate an enumeration with a tag\r\n\r\n```\r\n[@encoding enumeration]\r\n```\r\n\r\nor something similar, to inform ppx_deriving that the type is an en enumeration (if not that is an error) and should be encoded as a string, rather than as a list of objects.\r\n\r\n@zoggy Would it fit for you as well?"}}