1
{"response":"{\"reqEntityData\":{\"txnid\":\"YSCPAN99458555\",\"reqTs\":\"2023-08-19T16:54:34.118Z\",\"entityId\":\"SoftmintUAT\",\"dscProvider\":\"e-Mudhra Sub CA Class 2 for Document Signer 2014\",\"dscSerialNumber\":\"01589720\",\"dscExpiryDate\":\"03/03/2024 16:05:36 PM\",\"returnUrl\":\"https://uat.softmintdigital.com/panRes\",\"formData\":\"eyJhcHBsaWNhbnREdG8iOnsiYXBwbGlUeXBlIjoiQSIsImNhdGVnb3J5IjoiQSIsInRpdGxlIjoxLCJsYXN0TmFtZSI6IkJBSU4iLCJmaXJzdE5hbWUiOiJTVURJUFRPIiwibWlkZGxlTmFtZSI6IiIsImRvYiI6IjIwLzEyLzIwMDEiLCJnZW5kZXIiOiJNIiwiY29uc2VudCI6ZmFsc2UsIm5hbWVPblBhbkNhcmQiOiJTVURJUFRPICBCQUlOIiwia25vd25CeU90aGVyTmFtZSI6Ik4iLCJvdGhlclRpdGxlIjoiMCIsIm90aGVyTGFzdE5hbWUiOiIiLCJvdGhlckZpcnN0TmFtZSI6IiIsIm90aGVyTWlkZGxlTmFtZSI6IiJ9LCJwYXJlbnRzRGV0YWlscyI6eyJzaW5nbGVQYXJlbnQiOiJcdTAwMDAiLCJmYXRoZXJMYXN0TmFtZSI6IkFTRCIsImZhdGhlckZpcnN0TmFtZSI6IkFTRCIsImZhdGhlck1pZGRsZU5hbWUiOiIiLCJtb3RoZXJMYXN0TmFtZSI6IiIsIm1vdGhlckZpcnN0TmFtZSI6IiIsIm1vdGhlck1pZGRsZU5hbWUiOiIiLCJwYXJlbnROYW1lUHJpbnQiOiJGIn0sIm90aGVyRGV0YWlscyI6eyJwaHlQYW5Jc1JlcSI6IlkiLCJzb3VyY2VPZkluY29tZSI6eyJzYWxhcnkiOmZhbHNlLCJvdGhlclNvdXJjZSI6ZmFsc2UsImJ1c2luZXNzUHJvZiI6ZmFsc2UsImJ1c2luZXNzUHJmQ29kZSI6IiIsIm5vSW5jb21lIjpmYWxzZSwiaG91c2VQcm8iOmZhbHNlLCJjYXBpdGFsR2FpbnMiOmZhbHNlfSwiYWRkckZvckNvbW11bmljYXRpb24iOiIiLCJvZmZpY2VBZGRyZXNzIjp7ImZsYXRObyI6IiIsIm5hbWVPZlByZW1pc2VzIjoiIiwicm9hZCI6IiIsImFyZWEiOiIiLCJ0b3duIjoiIiwiY291bnRyeU5hbWUiOiJub25lIiwic3RhdGUiOiJub25lIiwicGluQ29kZSI6IiIsInppcENvZGUiOiIiLCJvZmZpY2VOYW1lIjoiIn0sImlzZENvZGUiOiI5MSIsInN0ZENvZGUiOiIiLCJ0ZWxPck1vYk5vIjoiODUwOTQzNTUxMyIsImVtYWlsSWQiOiJzdWRpcHRvYmFpbjhAZ21haWwuY29tIiwicGxhY2UiOiJTREFTRCIsImRhdGUiOiIxOS8wOC8yMDIzIn0sImFvQ29kZSI6eyJhcmVhQ29kZSI6IiIsImFvVHlwZSI6IiIsInJhbmdlQ29kZSI6IiIsImFvTm8iOiIifX0\\u003d\",\"authKey\":\"\"},\"signature\":\"BJZI+6SCmdVjM5j2Wab6vzIyaWEc9Mm7YnUP7wtL8fqN992hW7LI6fR4yq+QggTOkDawlLt3mgrIZaJeE8UD5Ie23OrrC1y42hpvpMBCihEsR+94+3je6Ia9DuiVriXPybtnyecnWcsnU8VQSMmekpxCOU3aF9nDVT6mVWwj1qZp8Id7ul2n/k9P5Npm4npWyP7fKFNqRCuv424jnJ537fO5g5yiuXSGlBFNKTgFL7YhVcNzYu4RUzvOHcQw9qnmZ1pwsFjoAjg+2ieWzjfyGlOw9fhmqbinaLd1Pc8AOHJRHWvmUlsAisueyOpZewEptAR+sCggsU5/prVZod5CBA\\u003d\\u003d\"}\n","status":"1"}

I Want To Remove Extra Slash , Unicodes , etc From This Json And Convert To Normal Json i am using str_replace For That But Also Its Fully Not Working ..

1 Answers1

1

You should find the cause of the slashes in your JSON, if you don't want them there. Removing them afterwards sounds like a patch for an mistake made earlier, and makes your code more complicated than needed.

To decode this you can use:

$object = json_decode($json);
$object->response = json_decode($object->response);

Assuming the JSON is in a string. Which results in:

(object) array(
   'response' => 
  (object) array(
     'reqEntityData' => 
    (object) array(
       'txnid' => 'YSCPAN99458555',
       'reqTs' => '2023-08-19T16:54:34.118Z',
       'entityId' => 'SoftmintUAT',
       'dscProvider' => 'e-Mudhra Sub CA Class 2 for Document Signer 2014',
       'dscSerialNumber' => '01589720',
       'dscExpiryDate' => '03/03/2024 16:05:36 PM',
       'returnUrl' => 'https://uat.softmintdigital.com/panRes',
       'formData' => 'eyJhcHBs................Tm8iOiIifX0=',
       'authKey' => '',
    ),
     'signature' => 'BJZI+6SCmdVjM................CggsU5/prVZod5CBA==',
  ),
   'status' => '1',
)

See: https://3v4l.org/NBeqS

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
  • `they shouldn't be there`...hmm, I'd argue they should, because it's JSON inside JSON so the escaping is necessary. What's probably not necessary is nesting it like that in the first place, so _that's_ what the OP should be trying to remove. Otherwise the answer is fine – ADyson Aug 19 '23 at 17:53
  • @ADyson I agree I am a bit vague there, but I was indeed addressing the nesting of JSON, which, I gathered from the question, is unwanted and makes decoding more difficult. Removing the premature encoding can help. – KIKO Software Aug 19 '23 at 17:58
  • OK. But I think you should edit it to clarify that merely crudely removing the slashes would not be adequate – ADyson Aug 19 '23 at 18:13