diff --git a/savejson.m b/savejson.m
index 24b671ca70626427038f13ec43c9cb891cf6907b..da6431d3aca4abd808f353fc51ec4bd904aedb5b 100644
--- a/savejson.m
+++ b/savejson.m
@@ -54,6 +54,9 @@ function json=savejson(rootname,obj,varargin)
 %                         1e999 to represent Inf, they can set opt.Inf to '$11e999'
 %        opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern
 %                         to represent NaN
+%        opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
+%                         for example, if opt.JSON='foo', the JSON data is
+%                         wrapped inside a function call as 'foo(...);'
 %        opt can be replaced by a list of ('param',value) pairs. The param 
 %        string is equivallent to a field in opt.
 % output:
@@ -98,6 +101,11 @@ else
     json=sprintf('{\n%s\n}\n',json);
 end
 
+jsonp=jsonopt('JSONP','',opt);
+if(~isempty(jsonp))
+    json=sprintf('%s(%s);\n',jsonp,json);
+end
+
 % save to a file if FileName is set, suggested by Patrick Rapin
 if(~isempty(jsonopt('FileName','',opt)))
     fid = fopen(opt.FileName, 'wt');