How do you describe a year (YYYY) in a JSON Table Schema?

Is this the correct way to describe a 4 character year field in a JSON Table Schema?

        {
        "name": "year",
        "description": "Year data was collected in e.g. 2016",
        "type": "date",
        "format": "fmt: %Y",
        "constraints": {
          "required": true
        }

Yes, this is the correct way to specify a 4 character year field in a JSON Table Schema.

The use of the fmt: prefix here is currently under discussion for removal. Here is the issue: Remove `fmt:` prefix for date formats · Issue #260 · frictionlessdata/specs · GitHub

edit: maybe remove the space between the %Y and the fmt:

1 Like

Thanks @danfowler. It’s confusing as when I use CSVLint to validate the data, this works:

         {
        "name": "year",
        "description": "Year data was collected in e.g. 2016",
        "constraints": {
          "required": true,
          "type": "http://www.w3.org/2001/XMLSchema#gYear"
        }

Looks like CSVLint and GoodTables are not 100% aligned.

1 Like

GoodTables says, “No” using…

    {
  "name": "YEARS",
  "description": "Year data was collected in e.g. 2016",
  "type": "date",
  "format": "fmt: %Y",
  "constraints": {
    "required": true
  } 

Using this data uploaded from local file (issues when accessing via URL).

Any clues?

Can you try removing the space between the fmt: and the %Y?

  "fields": [
    {
      "name": "YEARS",
      "description": "Year data was collected in e.g. 2016",
      "type": "date",
      "format": "fmt:%Y",
      "constraints": {
        "required": true
      }
    }
  ]
1 Like