2022.2

Table Of Contents
agementsystemslikeWordPress(requiresJSONAPIplugin)andDrupalprovideaJSONservice/API
toretrievecontent.
Note:
l
ThespecifiedJSONfileisexpectedtobeUTF-8,UTF-16orUTF-32encoded.Abyteorder
markspecifiedasthefirstcharacterwillbestripped.Savinganychangeswillchangethe
encodingtoUTF-8.
l
Loadjson()iscachedperbatchrun(basedontheURL)inprint/email.
l
ThisonlineJSONviewerishandytodebugJSONdata:http://jsonviewer.stack.hu
Tip: Externalcontentisnotloadedwhileeditingascript.Totestascriptthatloadsexternalcon-
tent,youcandoapreflight;see"DoingaPreflight"onpage818.
loadjson(location)
Loadsjsondatafromthespecifiedlocation.
location
String;thesuppliedlocationshouldbeeitheraURLorarelativefilepath.Thefileprotocolissup-
portedaswellasthehttp/httpsprotocols.ThecompletesyntaxofafullyqualifiedURLwiththe"file"
protocolis:file://<host>/<path>.Ifthehostis"localhost",itcanbeomitted,resultinginfile:///<path>,for
example:file:///c:/somefolder/somejson.json.
Examples
ThissamplescriptretrievesJSONdatafromasnippet.
var localJSON = loadjson('snippets/jsonsnippet.json');
if(localJSON.post){
results.html("<h3>" + localJSON.post.title + "</h3><p>" + localJSON.post.modified + "</p>");
}
ThisscriptretrievesapostfromaWordPresssite.
var wpPost = loadjson('http://192.168.101.58/2013/06/leave-the-third-dimension-behind-and-focus-on-real-printing-innovation/?json=1');
if(wpPost.post){ 
results.html("<h1>" + wpPost.post.title + "</h1>"
+ wpPost.post.content);
}
ThisscriptretrievesmultiplepostsfromaWordPresssite.
var numPosts = 3;
Page 1185