I am having some problems with fetching a JSON file using HTTP:retry
(or any of the other methods). The JSON file ends up looking like the picture below when I do ->body();
and then dd()
it:
I have attempted to do some cleaning with preg_replace (but not so good at regex), seems to partially work:
preg_replace( "/\r|\n/", "", $data );
Because the JSON looks like this it is not possible to do ->json();
it just returns null
when I then dd()
it. How can I can "clean" this properly so the result can be accessed as a normal JSON file?
Here is the output in text (missing the newlines (\n):
b"""
{
"devname":"Event Telt",
"devsn":"18940256",
"time":"14:54:53 2020-07-18",
"timeunix":"1595084093",
"synch":"1",
"ch1":
{
"name":"Temp Dataskap",
"unit":"°C",
"aval":"19.1",
"alarm":0
},
"ch2":
{
"name":"Temp Rom",
"unit":"°C",
"aval":"17.4",
"alarm":0
},
"ch3":
{
"name":"Fukt Rom",
"unit":"%RH",
"aval":"77.0",
"alarm":1
},
"ch4":
{
"name":"Channel 4",
"unit":"",
"aval":"n/a",
"alarm":0
},
"ch5":
{
"name":"Channel 5",
"unit":"",
"aval":"n/a",
"alarm":0
}
}
"""