output data from DataDefinition to json
Hi, wondering what the recommended way is to expose data from a DataDefinition to a third party application. Ideally we'd like to call a url from jquery that returns json. For instance on the example.com site there are two careers pages that use the Job Posting content type, Job posting Configuration set, and the Job Posting Data Definition. Seems like the technique would be similar to this thread http://help.hannonhill.com/discussions/how-do-i/20451-export-an-xml-file-to-local-server although when I view the xml output there are no xml tags surrounding the output, just the data entered into the data definition form fields? I guess I expected to see an xml document.
i see there is a JSON output type but we'd want to do this from the index page level, not the individual page level i.e. get back a json string with all of the Job Postings in the /company/careers folder..
Very new to Cascade here, so any help appreciated.
Thanks.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 03 Dec, 2015 07:46 PM
Hi Simon,
Currently, outputting XML as JSON is a bit more manual than simply dumping serialized XML. To summarize, you would need to loop over all of the XML elements and generate valid JSON markup using the node name and their escaped value. Additionally, you would need to use some recursion to handle any nested groups.
If you are using XSLT, I was able to find this related discussion which can provide an example for staters. It's a little older, so you'll want to replace
#START-ROOT-CODE
and#END-ROOT-CODE
with the newer#protect-top
code section. With that Format, you would set up your output to use the JSON type and have a template that looks like the following:To summarize, the
<pass-through>
element within the Template will allow you to work around the "root node" requirement for valid XML, and the#cascade-skip
will remove that element on render. The#protect-top
within your Format will move your content to the very top, resulting in a plain text file being generated.Please let me know if you have any questions.
Thanks!
2 Posted by sander on 07 Dec, 2015 12:10 PM
Ok thanks for that, I think that's doable. So the plain text file of json that is generated - I need to export that to the file system so it can be called from a url? Or does this all happen on the fly?
Thanks.
3 Posted by Ryan Griffith on 07 Dec, 2015 12:44 PM
Not a problem at all, Simon, let me know if you run into any roadblocks while writing the Format and I'd be happy to try and help out.
One your page output is generating the desired JSON, it would be published to your Destinations (ie web servers) as any other page would so it is publicly accessible.
Please let me know if you have any questions.
Thanks!
Ryan Griffith closed this discussion on 22 Dec, 2015 07:58 PM.