10 examples of 'url encode json' in JavaScript

Every line of 'url encode json' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
137function encode(object) {
138 if (typeof object === 'object') {
139 for (var property in object) { // jshint ignore:line
140 object[property] = encode(object[property]);
141 }
142 return object;
143 }
144 if (object !== null && object !== undefined) {
145 return encodeURIComponent(object);
146 }
147 return object;
148}
92function _encode(json) {}
112encode(json) { return super.encode(JSON.stringify(json)); }
15serialise (obj) {
16 var str = [];
17 for(var p in obj)
18 if (obj.hasOwnProperty(p) && obj[p] !== null && obj[p] !== '' && obj[p] !== undefined) {
19 str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
20 }
21 return str.join("&");
22}
5function json_encode(v) {
6 switch (typeof v) {
7 case 'string':
8 case 'number':
9 case 'boolean':
10 return json_encodeString(v);
11 case 'object':
12 if (v) {
13 if (v instanceof Array) {
14 return json_encodeArray(v);
15 } else {
16 return json_encodeObject(v);
17 }
18 } else return 'null';
19 }
20 return 'null';
21}
18function decode(url) {
19 return JSON.parse(Buffer.from(url.split('_cfg=')[1], 'base64'));
20}
7function urlBase64Decode(encodeStr){
8 return decodeURIComponent(atob(encodeStr));
9}
6function encode(obj){
7 var query = [];
8 forOwn(obj, function(val, key){
9 query.push( key +'='+ encodeURIComponent(val) );
10 });
11 return (query.length)? '?'+ query.join('&') : '';
12}
227function encodeSearchParams(obj) {
228 const params = [];
229 Object.keys(obj).forEach((key) => {
230 let value = obj[key];
231 params.push([key, encodeURIComponent(value)].join('='));
232 })
233 return params.length === 0 ? '' : '?' + params.join('&');
234}
85function encode(data) {
86 return encodeURI(data);
87}

Related snippets