I'm working on a logging tool for our software and I have ran into an issue with json_decode returning null and I was hoping to get some help.
The json object looks like this:
{
'id': 'string',
'request': {
'headers': {
...
},
'body': 'jsonstring'
},
'response' {
...
},
}
The problem is with the request->body part. Since its a a json object but saved as a string with quotations arround it, it seems to mess with the json_decode function and it returns null.
Editing the log entry to remove the quotation marks arround the body jsonstring in the request makes it go through, but this is how it is logged, and I'm not looking forward to potentialy having to rewrite the logging code. So any help is much welcome at this point.
Edit for the real JsonString being used. Removed auth and URLs however.
{
"payment_id": "1",
"type": "post",
"title": "Create Order",
"request": {
"headers": {
"Content-type": "application/json",
"Accept": "application/json",
"Authorization": "string"
},
"method": "POST",
"body": "{
"order": {
"items": [{
"reference": "8",
"name": "Test Product",
"quantity": 2,
"unit": "pcs",
"unitPrice": 12500,
"taxRate": 2500,
"taxAmount": 5000,
"grossTotalAmount": 25000,
"netTotalAmount": 20000
}, {
"reference": "test",
"name": "Test",
"quantity": 1,
"unit": "pcs",
"unitPrice": 20000,
"taxRate": 2500,
"taxAmount": 5000,
"grossTotalAmount": 25000,
"netTotalAmount": 15000
}, {
"reference": "1",
"name": "Flat rate",
"quantity": 1,
"unit": "pcs",
"unitPrice": 6125,
"taxRate": 2500,
"taxAmount": 1225,
"grossTotalAmount": 6125,
"netTotalAmount": 4900
}],
"amount": 56125,
"currency": "SEK",
"shipping": {
"costSpecified": true
}
},
"checkout": {
"url": "",
"termsUrl": "",
"shipping": {
"countries": [],
"merchantHandlesShippingCost": true
},
"consumerType": {
"supportedTypes": ["B2C"]
}
},
"notifications": {
"webHooks": [{
"eventName": "payment.reservation.created",
"url": "",
"authorization": ""
}]
}
}"
},
"response": {
"headers": {},
"body": {
"errors": {
"notifications.WebHooks[0].Url": ["Field is not accepted as a valid URL"]
}
},
"response": {
"code": 400,
"message": "Bad Request"
},
"cookies": [{
"name": "visid_incap_1152497",
"value": "2qY5gE/QT6W4CmOH1cLUuig yFsAAAAAQUIPAAAAAABsjnmr3oFW5wXzhutW3EWq",
"expires": 1571353603,
"path": "/",
"domain": "api.dibspayment.eu"
}, {
"name": "incap_ses_273_1152497",
"value": "hXtkOPG/TwEHQCnMhuTJAyg yFsAAAAALrqG9pupkT/7iEMdOohRTw==",
"expires": null,
"path": "/",
"domain": "api.dibspayment.eu"
}],
"filename": null,
"http_response": {
"data": null,
"headers": null,
"status": null
}
}
}