-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function jokes=random_json_joke(num, url) | ||
% this example shows how to use the _DataLink_ annotation defined in the | ||
% JData specification | ||
% (https://github.com/NeuroJSON/jdata/blob/master/JData_specification.md#data-referencing-and-links) | ||
% to define linked JSON/binary JSON data using external files or URL on the | ||
% web. In the below example, the jokeapi.dev feed returns a JSON record via | ||
% RESTFul URL, the returned record contains a subfield called `joke`, which | ||
% can be retrieved via the JSONPath $.joke attched after the URL, separated | ||
% by a collon. The general _DataLink_ URL is in the form of "URL:$jsonpath" | ||
|
||
if(nargin==0) | ||
num=1; | ||
end | ||
|
||
if(nargin<2) | ||
url='https://v2.jokeapi.dev/joke/Programming?type=single'; | ||
end | ||
|
||
joke.(encodevarname('_DataLink_'))=[url ':$.joke']; | ||
jurl=savejson('',joke); | ||
|
||
jokes=cell(1,num); | ||
for i=1:num | ||
jokes{i}=loadjson(jurl, 'maxlinklevel',1); | ||
end | ||
|
||
if(num==1) | ||
jokes=jokes{1}; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters