Home > Software design >  JSON data.kind convention - how to populate?
JSON data.kind convention - how to populate?

Time:03-27

I saw this data.kind convention in Google's JSON Style Guide and I'm wondering what is a good way to populate this data? Specifically I'm working with express.js and MongoDb.

Is it typically part of the DB schema and saved in the DB? Or would it get added to the data in the server before the res.json happens?

CodePudding user response:

Well, as said in the description of the kind convention

The kind property serves as a guide to what type of information this particular object stores

{"data": {"kind": "album"}}

This property is more a guide than a data to be stored, so it seems to fit naturally at the response level, it's not something that you want to store. If you pay attention to the example, you can see that the kind is similar to the schema's name of your DB.

Another example is in the data.fields, take a look:

{
  "data": {
    "kind": "user",
    "fields": "author,id",
    "id": "bart",
    "author": "Bart"
  }
}

it's likely that you will store things about an user, but not the kind field by itself. In both examples the kind looks like the schema's name, so maybe you can use the schema's name as the kind field, but remember that each case is different, take your own conclusions and use what fit better in your case. Hope i clarified things a bit!

  • Related