Simplicty and flexibility!


How easy it is to create JSON from DG3

Started by DataEase Development
You will need to Sign In to be able to comment on the Blog!

How easy it is to create JSON from DG3

A lot of web sites delivers data to it's users as a JSON object. The beauty of this format is that it can be parsed and used by almost any web developer framework and used directly in java-script without any extra work converting it. A DG3 user asked me if it is difficult to create JSON output from DG3 and that is what led to this blog entry.

DG3 do not yet have JSON as output format from transfer, but you can easily create this format using a blank, template and a page with two boxes and a dataview.

This is how to make an object with a named object containing an array of arrays with strings:

First make sure you have a blank base template. That is a template with only a:

{% block content %}{% endblock %}

Then create a new page and add an extra dataview and a box. The order should be box, dataview and box and make sure that outer html is turned of in all three.

Then make all into html type elements.

Then make the start tag for JSON in the first box to the object type you vant to use

{

"info" : [

Then select the data table for the dataview and add all the live text in proper JSON notation and make sure you do not have any closing comma in the last element in the array. Make sure you enclose all string with a " and not a ' as that will fail in a lot of parsers out there.

["[{ viewdata.From }]","[{ viewdata.To }]","[{ viewdata.Text }]","[{ viewdata.Comment }]"][% if forloop.last %][% else %],[% endif %]

Then you close off the JSON in the last box

]}

That's it. Now you can deliver you data in JSON. This method can be used to create any text format you ever need to deliver to external sources.


Written by DataEase Development 12/12/13 at 08:55:29 DataEase Generation 3
DG3_BlogList