you should debug it looking at the actual response sent by your Moodle server: unfortunately Moodle doesn't show you the plain response in case of issues like yours about a malformed JSON so you need to capture and inspect it by your own, by "simply" using the Developer Tools of your browser.
An example about how to do it for a different issue: https://tracker.moodle.org/browse/MDL-60691?focusedCommentId=597479&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-597479
Thank you, Matteo and every one in the thread!
It's very strange but it was an issue with the browser. I came to know when I open ran it on the hosted server. It seems to me like this is an issue on updated browsers because same process works on older versions. Thank you again.