Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Build a feature supplying a view for /data.json
Comment | File | Size | Author |
---|---|---|---|
#2 | project_open_data-view.patch | 38.9 KB | grasmash |
Comments
Comment #1
grasmash CreditAttribution: grasmash commentedTaking this!
Comment #2
grasmash CreditAttribution: grasmash commentedChanges pushed to repository. Patch attached. Please review!
Comment #3
Barrett CreditAttribution: Barrett commented@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
The distribution field also does not seem to be rendered correctly.
Comment #4
grasmash CreditAttribution: grasmash commentedInteresting. 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.
Comment #5
grasmash CreditAttribution: grasmash commentedOk, got the general output looking better, but still need to work on the distribution field.
Considering a custom views handler or display formatter to handle the distribution field.
Comment #6
grasmash CreditAttribution: grasmash commentedAck, 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().
Comment #7
Barrett CreditAttribution: Barrett commentedVery interesting.
Even on the preview though, the distribution field is borked.Ha! You added more comments while I was readingComment #8
Barrett CreditAttribution: Barrett commentedThat'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.
Comment #9
grasmash CreditAttribution: grasmash commentedI 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.
Comment #10
grasmash CreditAttribution: grasmash commentedChanges have been merged into 7.x-1.x.
Comment #11
Barrett CreditAttribution: Barrett commentedThe 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.
Comment #12
acouch CreditAttribution: acouch commented@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!