I have a requirement to allow a client to only request a subset of fields from a large json schema. I have done this using ODATA and their concept of $select (I like a lot about ODATA. Except the lack of adoption) I know I can spin my own solution but feel there must be other open source solutions I can use or use as a base. ( my service is in go)
Does anyone know of something similar? Common conventions?
Adding some clarification:
Say I have a schema like the following:
{ "status": { "enum": [ "active", "inactive" ] }, "lastModified": { "type": "string", "format": "date-time" }, "userId": { "type": "string", "minLength": 1 }, "username": { "type": "string", "minLength": 1 }, "firstName": { "type": "string", "minLength": 1 }, "lastName": { "type": "string", "minLength": 1 }, "email": { "type": "string" }, "address": { "$ref": "#/definitions/address" } }
By default, a GET to our User resource will return all of these fields. What I would like is a way for a client say they just want something like the following:
{ "firstName": { "type": "string", "minLength": 1 }, "lastName": { "type": "string", "minLength": 1 }, "email": { "type": "string" } }
Using Odata you can specify this with a $select querystring argument. Ideally, I'd like to have a client specify the schema they would like and we just pass the full schema through a, sort of, filter that does just this each time. But, I feel that will likely be something I'll have to code myself. But, in the short-term, if there is a way to have a client specify the fields they want in this way per request, they would be satisfied until we get something a bit more robust.
If i understood your question correctly you want to reveal the client specific fields. If thats the case you can use Json tags like that.
type FileMD struct {
FileName string `json:"filename"`
FileSize int `json:"filesize"`
FileMD5 string **`json:"-"`**//this wil ignore the FileMD5 field
}