This question already has answers here:
Why does this PHP code just echo "Array"?
(6 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 2 years ago.
I have an JSON Export from a REDCap and it started as a nested ARRAY. I use json_decode, but when I print the result I get an ERROR.
Here is the Array:
[{"record_id":"13","lastname":"Mustermann","first_name":"Json","dob":"1948-10-12","case_number":"1366613"}]
My Code is:
$deco = json_decode($json);
print $deco;
The line "echo" gives an error. What am I doing wrong?!
Thank you
Related
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
I have a JSON output that looks like this:
{"data":[{"QID":"Q1234","MgrQID":"5678","NTID":"blah"}]}
I am trying to access just the data within the square brackets, inside the data array?
I have tried $jsonVar['data'] and $jsonVar->data and neither of them are working.
Is there a way I can just get access to [{"QID":"Q1234","MgrQID":"5678","NTID":"blah"}]?
Try this example:
<?php
$data = '{"data":[{"QID":"Q1234","MgrQID":"5678","NTID":"blah"}]}';
$test = json_decode($data, true);
echo json_encode($test['data']);
?>
Output:
[{"QID":"Q1234","MgrQID":"5678","NTID":"blah"}]
This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
I want to get the URLS from the JSON below.
$jsonArray = {
"uuid": "signed",
"PreSigned": "{'url': ['www.g.com', 'www.o.com']"}
I tried this $jsonArray -> PreSigned[0]->url
And it didn't work
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 6 years ago.
I have a json text like this:
$text ='{"id":"12","count":"1","1":{"gkey":"g_c5218"},"0":{"gkey":"g_4b4c6"}}';
I want convert it to array:
$arr = json_encode($text,true);
Now I want call $arr['id'] But I get index error.
what is my wrong?
json_encode() - change an array to the json
json_decode() - change json to the array/object
You should use json_decode.
This question already has answers here:
json decode in php
(5 answers)
Closed 8 years ago.
How to spit this set of data using php? this data generated from some php to my mysql database.
[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"Destination Queenstown"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Ella Zhang"}]
now i just need to get id=2 and its value in the output.
It is a JSON data.Try with -
$array = '[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"Destination Queenstown"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Ella Zhang"}]';
$array = json_decode($array);
echo $array[1]->id;
This question already has answers here:
Trying to parse JSON with PHP
(2 answers)
Accessing JSON array after json_decode/multidimensional array
(3 answers)
Closed 8 years ago.
I am receiving a multilevel json like this:
{"id":"3",
"field2":"ssss",
"field3":[
{"field31":"wwwww",
"field32":"qqqq"},
{"field31":"wwwww",
"field32":"qqqq"},
{"field31":"wwwww",
"field32":"qqqq"},
]}
I am reading json values (first level) like this in php:
$json = file_get_contents('php://input');
$json_post = json_decode(utf8_decode($json), true);
$id = $json_post['id'];
But I don't know how to get the json in the second level. What is the simplest way? I just need to get the json in other variable like $json_post, I will read it in a for bucle to get each row of the json file
It's going to give you a PHP object if you run json_decode(utf8_decode($json));
echo $json_post->field3->field31;
EDIT: I missed that you were using the conversion to array. This is what the array would look like
echo $json_post['field3']['field31'];