sakshik

JSON FreeMarker Alfresco

Blog Post created by sakshik on Aug 4, 2017

Steps to get JSON data from calling a webscript through curl command.

 

Suppose your javascript has an array of node objects of Alfresco and you want to print their names and paths in json format:

 

Step 1: Create a file testjson.get.xml in ..Data Dictionary/Web Scripts

<?xml version="1.0" encoding="UTF-8"?>
<webscript>
<shortname>test</shortname>
<description>test</description>
<authentication>user</authentication>
<url>/testjson</url>
</webscript>

 

Step 2: Create a file testjson.get.js which has the array you want to get in json format

 

docnodes = [node1,node2,node3]; // array of nodes of alfresco

model.docnodes = docnodes; // to be able to use this array in json ftl file

 

Step 3: Create a file testjson.get.json.ftl

 

[
<#list docnodes as d>
{
"name" : "${d.name}",
"path" : "${d.displayPath}"
}<#if d_has_next>,</#if>
</#list>
]

 

Step 4: 

Go to https://<hostname>/alfresco/service/

Click Refresh Web Scripts to register your new webscript

 

Calling through curl command:

 

curl -s -u "<username>":"<password>"  "https://<hostname>/alfresco/service/testjson.json"

 

Outcomes