Build a feature supplying a view for /data.json

CommentFileSizeAuthor
#2 project_open_data-view.patch38.9 KBgrasmash
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

grasmash’s picture

Assigned: Unassigned » grasmash

Taking this!

grasmash’s picture

Status: Active » Needs review
FileSize
38.9 KB

Changes pushed to repository. Patch attached. Please review!

Barrett’s picture

Version: » 7.x-1.x-dev
Status: Needs review » Needs work

@madmatter23: it looks like this has already been merged. Can you confirm?

It looks like there are a couple problems with the json. With one dataset node, I'm seeing the output below. The opening doesn't line up with what's in the example json at http://project-open-data.github.io/examples/catalog-sample-extended.json

{"0":{"title":"Data Catalog","description":"Data Catalog","keyword":"catalog","modified":"2013-08-16","publisher":"Agency.gov","person":"Lastname, Firstname","mbox":"","identifier":"catalog","accessLevel":"Public","accessURL":"JSONDownload URL: http://default/data.json\nFormat: json\nSize : \n"}}

The distribution field also does not seem to be rendered correctly.

grasmash’s picture

Interesting. The preview in the Views UI shows output that matches the open data standards, but the actual output of the JSON at data.json differs. Seems like this could be a bug in views_datasource which, to be fair, is a dev version. I wonder if we can find an alternative or patch it.

grasmash’s picture

Ok, got the general output looking better, but still need to work on the distribution field.

[
  {
    "title" : "test",
    "description" : "test",
    "keyword" : "test",
    "modified" : "2001-01-01",
    "publisher" : "test",
    "person" : "test",
    "mbox" : "example@example.com",
    "identifier" : "58466926-97d9-49b4-a232-be7d01298561",
    "accessLevel" : "Public",
    "accessURL" : "JSONDownload URL: test\nFormat: json\nSize : \n"
  }
]

Considering a custom views handler or display formatter to handle the distribution field.

grasmash’s picture

Ack, looks like views datasource doesn't play well with nested array or object in its output.
#1699368: #RVDA: Rewrite Views Datasource's Architecture
#1319714: Fields with multiple values are not displayed

This makes me consider outputting the JSON programmatically by building up and object structure in code outputting with drupal_json().

Barrett’s picture

Very interesting.

Even on the preview though, the distribution field is borked. Ha! You added more comments while I was reading

Barrett’s picture

That's a shame, but I don't see a better solution unless we want to help Views Datasource with the rewrite they have been discussing for the past year and haven't completed.

grasmash’s picture

Status: Needs work » Needs review

I created a new branch that generates the data.json output programatically. I don't think there is supposed to be any paging for data.json, so I don't think views actually offers that much. This also reduces dependencies.

Checkout git branch: manual-json-output.

grasmash’s picture

Changes have been merged into 7.x-1.x.

Barrett’s picture

Status: Needs review » Fixed

The JSON looks good, Matt. Putting it through Project Open Data's validiator (http://project-open-data.github.com/json-validator/) complains about it lacking a data dictionary element, but I think that's a fault with the validator and not the JSON.

acouch’s picture

@Barrett and others, please comment on this pull request: https://github.com/project-open-data/json-validator/pull/6 The JSON validator is not working correctly which is a hinderance to any adopters Drupal or otherwise. Great work!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.