Support non-"application/json" MIME types #7

Closed
bhollis opened this Issue Oct 1, 2011 · 25 comments

Projects

None yet

10 participants

@bhollis
Owner

JSONView should be configurable to support nonstandard JSON MIME types in addition to "application/json"

@rhunter

As noted in the Google Code issue, the pattern application/*+json would cover a lot of the use cases (notably application/vnd.*+json and application/prs.*+json).

Of course, the browsers may or may not currently support registering a handler for patterns, so this ticket is more of a placeholder until they do :-(

@bhollis
Owner

Thanks for the note, and that would be nice, but I'm unaware of any way to register content-handlers for MIME type patterns in Firefox. If anyone figures out a way, I'd appreciate a pull request.

@chooh

Is it possible to use JSONView with Open in Browser plugin? I think such integration will solve most of issues.

@BrianARice

text/json would definitely be appreciated

@bhollis
Owner
@BrianARice

because, for some bizarre reason, inside an iframe, inside IE 8(?), inside an ajax call... when I return application/json... it tries to download a file... but, it seems not to with text/json... so, at the moment... my server code says if it's firefox return application/json (so this thing works)... otherwise application/json... so it would be nicer to just have this thing work with a few non-standard and/or user defined mime types.

@bhollis
Owner

Gotcha. The way I'd like to see this feature implemented in JSONView is as a list of MIME types in a list in the JSONView options. Initially it would be populated with only "application/json", but people could add more types as they require.

@cwilkes

SOLR at least until 3.5 returns "text/plain" for a json response. It would be handy if jsonview would accept a list of urls that it should handle the display for -- I have a set list of SOLR servers that I hit all the time. Is there another way to do this? It is really annoying to see a long string of text when I'm used to jsonview's goodness.

@bhollis
Owner

@cwilkes as I said above, I'd like to just have JSONView be customizable to accept whatever crazy MIME types you want.

@bbailleux

Sometimes, some servers (probably wrongly configured) use exotics Mime Types. So it will be nice to be able to add some other Types, like text/json.
Furthermore, having a menu entry to See with JSONView will be great when the content is text/plain (because this Mime Type is sometimes JSON, often something else, so adding it in the Options is non-sense).

@bhollis
Owner

Yes, that is indeed what this feature request is about.

The second part, about forcing a page to render as JSON from a menu, is #5.

@konklone

Sorry to file the dupe. But I don't think you should just make JSONView configurable to support alternative mime-types. JSONView should recognize application/*+json as JSON - because that's what the mime type says it is. The burden shouldn't be on individual users to add each one they come across.

@bhollis
Owner
@konklone

OK, then better idea - if you need to catch explicit mime type strings, how about extracting the list of mime types you catch to a single text file in this repo? Then, people can start contributing mime types as they find them. That way, when annoying people like me start ragging on you, you point them at the file and tell them to click the "Edit" button.

@dotnetCarpenter

I think that is a good compromise.

@bhollis
Owner

Sounds good for application/json+*, feel free to send a PR.

@konklone

I'm new to Firefox extensions - I cloned the repo and grepped through mentions of application/json, but there's a lot. Would it be easy enough for you to extract the core uses of application/json out to a text file with just one entry? Or to give me a clue as to where to start myself?

@bhollis
Owner

I'm actually not sure myself how to do it - Currently the thing that makes it work is some combination of this line: https://github.com/bhollis/jsonview/blob/master/src/chrome.manifest#L23 and this one https://github.com/bhollis/jsonview/blob/master/src/components/jsonview.js#L210 - I remember that this was related to some change in Firefox at some point, so I don't remember whether both or needed or if it's just one or the other. I also don't know how to programmatically add contracts if it's really coming from the chrome.manifest (which I think it is). I know there's an API now for it, but it may require completely re-doing how JSONView is initialized and registered (by changing it to a new-style bootstrapped extension).

@konklone

Wow, okay. Writing an old-style Firefox extension looks like not a lot of fun. It does look like this is best done as part of a larger refactor into a new-style HTML/CSS/JS based extension.

Sounds like a fun project, maybe I'll learn how to do it. Do you think JSONView could be done as a new-style extension?

They have a migration guide and an old vs new breakdown. The tabs API has an experimental contentType property that says:

Returns the MIME type that the document currently loaded in the tab is being rendered as. This may come from HTTP headers or other sources of MIME information, and might be affected by automatic type conversions performed by either the browser or extensions. This property is read-only.

@honzajavorek

+1, this is really needed with hypermedia APIs approaching - a lot of new JSON mimetypes appear:

  • application/vnd.collection+json
  • application/vnd.hal+json
  • application/vnd.siren+json
  • application/vnd.mason+json
  • ...
@bhollis
Owner

Again, I have no argument that this would be a good feature to implement, and I would be happy to look at a pull request from somebody who did so.

@konklone

How straightforward would a rewrite as a new-style Firefox extension be? Could it share much code with the popular Chrome extension's code?

@eduard93

text/json still seems to be unsupported.

@bhollis
Owner
@bhollis bhollis added a commit that closed this issue May 30, 2015
@bhollis Support user-defined additional content types to treat as JSON. This …
…is a potentially dangerous option that may be reverted if it causes problems. Fixes #7.

This also fixes preferences handling that was broken in 756fa51.
6fd4d62
@bhollis bhollis closed this in 6fd4d62 May 30, 2015
@bhollis
Owner

This will be in the upcoming JSONView 1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment