So I have this main URL
myapp://page/open-slideup-menu?params=${encodeURIComponent(JSON.stringify(this._getDeeplinkParams()))}
The _getDeeplinkParams
function returns and nested JSON object like
{
header_text: 'Post Options',
cancel_text: 'Cancel',
options: optionsArray
}
The optionsArray
is as array that has nested JSON that can contain URL in them as well ..
const deletePostAction = {
url: `https://api.com/posts/XXX`,
method: 'DELETE'
};
const deletePostOption = {
text: 'Delete',
action: {
url: `myapp://page/delete-item?id=XXX&action=${JSON.stringify(deletePostAction)}`,
}
};
optionsArray = [deletePostOption];
As you can see the options array has a nested JSON with URL inside of it.. I need to stringify the URL inside the deletePostOption
..
But it stringifies it twice and produces an unparsable main deeplink..
myapp://page/open-slideup-menu?params={"header_text":"Post Options","cancel_text":"Cancel","options":[{"text":"Delete","action":{"url":"myapp://page/delete-item?id=XXX&action={\"url\":\"https://api.com/posts/XXX\",\"method\":\"DELETE\"}"}}]}
the nested second URL in the has \" in it .. SO that makes it inparsable..
Any clean way of doing this without .replace(/^\\"g/,'"')
, so that all the urls are and deeplinks are properly encoded and it works for more nested urls
My ideal output would be something like this
myapp://page/open-slideup-menu?params={"header_text":"Post Options","cancel_text":"Cancel","options":[{"text":"Delete","action":{"url":"myapp://page/delete-item?id=XXX&action={"url":"https://api.com/posts/XXX","method":"DELETE"}"}}]}
Or if any other standard output used in production systems please let me know