Is `media` part of the json schema specs?

32 views
Skip to first unread message

Mihai B

unread,
Apr 4, 2016, 10:23:31 AM4/4/16
to JSON Schema
I need to represent a property  whose value is a base64 encoded image/png. It seems there is a `media` keyword but it is available only in the hyper-schema specification[0]. Why is that? The data provider is not an API so hyper-schema doesn't make much sense to the project.  Shouldn't `media` be part of the json schema specifications[1].


Austin Wright

unread,
Apr 5, 2016, 8:17:45 AM4/5/16
to JSON Schema
I think your schema should be sufficient with simply {type:"string"} in this case.

The hyper-schema is aimed at user-agents that want to consume JSON as hypermedia -- documents with embedded resources, and URIs pointing to other documents, and establishing relationships between documents. But the few extra keywords that it defines aren't used for validation (e.g. it doesn't perform "ensure that the attached string decodes to a valid image/png"), so I'm not sure it'd be getting you anything useful.

If you are writing an endpoint that *can* make use of hypermedia, then just specify use of the hyper-schema with:



Austin.

Mihai B

unread,
Apr 13, 2016, 7:35:49 AM4/13/16
to JSON Schema
I'm generating a client from json schema and the issue is that I would rather prefer to use a slice of bytes ([]byte) instead of strings. If the encoding(i.e. base64) is available I can also hook a decoder to avoid manual labor so that the client doesn't need to deal with the string to []byte conversion and base64 decoding. The field may be a property of an object so I don't think hyper-schema media can help because it describes the media of the link not of an individual property. 
Currently I've just added a `media` field in my schema implementation. I've also considered dumping it into "format" though I don't know if that would make it worse(i.e. more non-compliant with the standard)

Mihai.
Reply all
Reply to author
Forward
0 new messages