Search

How difficult would write an extension that adds a datasource type for JSON. I would like to create something that works almost exactly like the dynamic XML DS type except it would read the JSON data and convert it to XML.

In this blog post Craig mentions that datasource types will be abstracted in 2.1, which I assume would make it a lot easier to do what I want to do. Would it even be worth it right now, or should I wait for 2.1?

The Content Type Mappings extension is your friend.

Yep this can be done with existing Data Sources. Define your DS as usual, attach it to a page, and use the Content Type Mappings to output the page as plain text (or application/json or whatever you prefer). You can then use XSLT to transform the DS XML into JSON (e.g. the XML to JSON utility).

The abstractions of Data Sources in 2.1 I think is more down to the origin of the data (Authors, Navigation, Sections, other data stores…) rather than the way the data is output. I believe the output of a Data Source will always be XML, and you transform to taste using XSLT.

I would like to create something that works almost exactly like the dynamic XML DS type except it would read the JSON data and convert it to XML.

I think brentburgoyne wants to read JSON and output the data as XML.

There is no need for an extension or to wait for 2.1 to do this. You could create a dummy dynamic XML DS and modify it, especially the grab-function.

Oh you’re right, I totally misread the first comment! Sorry. Please disregard everything I said because it is wrong :-P

I’ve got a few situations where this would be really cool (reading remote JSON data into Symphony). It wouldn’t be too difficult to use PHP’s JSON serializer to transform remote feeds into XML data - when I finish up my current contracts I’ll take a look at some form of intermediary.

Heh, me too. Ignore everything I say.

I think the dynamic datasource functionality has alot of potential for extension. Not only parsing JSON, but also authenticated HTTP requests to get into secure resources such as S3 stores, etc.

Thanks for you help everyone. I have created this hack of an extension that works for now. In the future I would like to figure out how to make everything work without needing to edit the datasource file.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details