Forum Index

No notifications
Notifications

Favorites

No favorites found
What`s New Discover new product features and functionality
Announcements > What`s New > New JSON Support in CDS View modes: 
User avatar
KnowledgeKube Staff
KnowledgeKube Staff
Gary T - 30/05/2017 15:34:36
   
New JSON Support in CDS

The next release of KnowledgeKube includes a number of features that let you generate, fetch, and manipulate data using JavaScript Object Notation, also known as JSON. This lightweight, human-readable notation can be interpreted by a wide range of systems, and is completely language-independent.

These extensions are currently only available in the HTML editor; we hope to have an update soon that includes a much simpler user experience making management and re-use simpler.

Enjoy!

Generating your own JSON is as simple as deploying an Element Tag into page markup, defining the values you want to include, and specifying a keyword with which to store the resulting data. An example of this element is shown below:

<%# GENERATEJSON(
        Keyword="PostDataJSON"
        CompanyName="My_Company"
        ProductGuids="[null]"
        ProductMetaTagGuids="[list]"
           ProductMetaTagGuids="8a18f3e5-5e95-4035-995c-d7d73f4a749a"
           ProductMetaTagGuids="7e962b07-6d66-4538-a5d6-375a3f3b8d24"
        CompanyLevel="[1]") %>

If you need to fetch data from a remote API, you can either use an element tag or a KnowledgeKube parser function. Both options let you query the API and store the results of that query in a keyword.

An example of an element tag that queries an API is shown below:

<%# EXECUTE(
        RequestUrl="https://jsonplaceholder.typicode.com/users"
        IsAuthenticated="false"
        Keyword="UserDetails") %>

An example of a parser function call that fetches JSON from an API is shown below:

JSONResponse:= ServiceRequestJSON( "http://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400", "GET" );

When you have the JSON data you need, you can perform a number of operations on it – including retrieving individual values, adding new ones, and updating or deleting existing ones. You have a wide range of options here, including using the DATA element tag to render a value on a web page, the DATAFILTER tag to assign a filtered version of the data to a keyword, or the ParseJSON function to manipulate a string of JSON data. You also have the option to pass it into a remote source, which can either be the original source or an alternative one.

The following example demonstrates an element tag that uses a POST operation to update remote data:

<%# EXECUTE(
        PostDataKeyword="UserDetails"
        RequestUrl="https://mysite.com/users"
        IsAuthenticated="false") %>

Similarly, you can use the ServiceRequestJSON function to perform either a PUT (write), POST (overwrite) or DELETE operation on remote data, as demonstrated by the following example:

ServiceRequestJSON( "http://api.sunrise-sunset.org/json?lat=36.7201600&amp;lng=-4.4203400", "POST", "NewResultsJSON" );

You can use JSON with a Wrap-around Element to control the visibility of page content. If the result of the nested expression is True, the wrapped content will be displayed. Otherwise, it will be hidden, as demonstrated by the following example:

<%= ISDATATRUE(
        Keyword="ProductData"
        Path="results"
        Type="Count"
        Name="TotalProducts"
        Expression="TotalProducts = 0;") %>
             <p>No products in category.</p>
<%= %>

You can use an element tag to render individual JSON values from session data. An example of this is shown below:

<%# DATA(
        Keyword="UserDetails"
        Path="user.name") %>

The DATAROW element returns rows from a specific array within the target JSON, while a nested DATA element presents a value from each row in that array, as shown below:

<%= DATAROW(
        Keyword="ProductsJSON"
        Path="ProductID"
        Name="ProductIDRow"
        MaxRows="10"
        StartRow="0") %>
              <p><%# DATA(keyword="ProductsJSON" path="ProductIDRow") %></p>
<%= %>


RSS Feed