Issues in json_encode [duplicate] - php

This question already has answers here:
Best way to create an empty object in JSON with PHP?
(4 answers)
Closed 6 years ago.
I have this array:
$array = [
"stored_fields" => ["id"],
"match_all" => []
];
I want:
{"stored_fields":["id"],"match_all":{}}
But, When I call:
echo json_encode($array);
I got:
{"stored_fields":["id"],"match_all":[]}
If I use:
echo json_encode($array, JSON_FORCE_OBJECT);
I got:
{"stored_fields":{"0":"id"},"match_all":{}}
What I can do?

There might be a better way, but you can just force an object:
$array = [
"stored_fields" => ["id"],
"match_all" => (object)[]
];
You could also use (object)null. Anything else will result in {"scalar":someting}. Another option is new stdClass.

Related

How can I do this change in json? [duplicate]

This question already has answers here:
Pretty-Printing JSON with PHP
(27 answers)
Closed 1 year ago.
Hi I have php code which I use json_encode to create from an array a json code, the thing or porblem is that json_encode becomes the array to a lineal json what I mean it this:
$data["auth"]["cert"] = ["-----BEGIN CERTIFICATE-----\nMIIGjjCCBXagAwIBAgIDAR4jMA0GCSqGSIb3DQEBCwUAMIGmMQswCQYDVQQGEwJD\nTDEYMBYGA1UEChMPQWNlcHRhLmNvbSBTLkEuMUgwRgYDVQQDEz9BY2VwdGEuY29t\nIEF1dG9yaWRhZCBDZXJ0aWZpY2Fkb3JhIENsYXNlIDMgUGVyc29uYSBOYXR1cmFs\nIC0gRzQxHjAcBgkqhkiG9w0BCQEWD2luZm9AYWNlcHRhLmNvbTETMBEGA1UEBRMK\nOTY5MTkwNTAtODAeFw0yMTA3MDgyMzQwMjZaFw0yNDA3MDgyMzQwMjZaMIGXMQsw\nCQYDVQQGEwJDTDEYMBYGA1UEDBMPUEVSU09OQSBOQVRVUkFMMSswKQYDVQQDEyJN\nQVJDRUxPIEFMRUpBTkRSTyBJTlpVTlpBIEdPTlpBTEVssaMSwwKgYJKoZIhvcNAQkB\nFh1DUklTVElBTklOWlVOWkFASklTUEFSS0lORy5DTDETMBEGA1UEBRMKMTAwMzM3\nNDEtSzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBA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plbEH0IqOP84tGNnKRx9bq4oHGk2wENHH\nc/feGzdrVPgkQ6CVGFWQV39MJDoGDVgYrz7d3t3bAoGBAK+UnIFrRJ225UMsIM5Ao2\nryKtwPemdHypIVK3WOV1yRpa5aBqemrTQkijbLx8lVxoeID8Lw4zHybK6V9mAHsf\nRhfHsmBz3f4mYoKVoyVDelxpx+IGkGibvzNQB5BFWuu8kZeDPkhcPbk4pHFUf/jm\nCvLdtcSmumV5hxnVdtwjdlQD\n-----END PRIVATE KEY-----"];
$data["emisor"] = "76063822-6";
$data["resolucion"] = ["fecha" => "2014-06-17", "numero" => 57];
$data["secuencia"] = 1;
$data["documentos"][] = [
"TpoDoc" => 39,
"NroDoc" => 3,
"TasaImp" => 0,
"FchDoc" => "2021-07-05",
"MntExe" => 100,
"MntNeto" => 0,
"MntIVA" => 0,
"MntTotal" => 100
];
$data = json_encode($data);
That array becomes to this:
{"auth":{"cert":{"cert-data":"-----BEGIN CERTIFICATE-----\nMIIGjjCCBXagAwIBAgIDAR4jMA0GCSqGSIb3DQEBCwUAMIGmMQswCQYDVQQGEwJD\nTDEYMBYGA1UEChMPQWNlcHRhLmNvbSBTLkEuMUgwRgYDVQQDEz9BY2VwdGEuY29t\nIEF1dG9yaWRhZCBDZXJ0aWZpY2Fkb3JhIENsYXNlIDMgUGVyc29uYSBOYXR1cmFs\nIC0gRzQxHjAcBgkqhkiG9w0BCQEWD2luZm9AYWNlcHRhLmNvbTETMBEGA1UEBRMK\nOTY5MTkwNTAtODAeFw0yMTA3MDgyMzQwMjZaFw0yNDA3MDgyMzQwMjZaMIGXMQsw\nCQYDVQQGEwJDTDEYMBYGA1UEDBMPUEVSU09OQSBOQVRVUkFMMSswKQYDVQQDEyJN\nQVJDRUxPIEFMRUpBTkRSTyBJTlpVTlpBIEdPTlpBTEVaMSwwKgYJKoZIhvcNAQkB\nFh1DUklTVElBTklOWlVOWkFASklTUEFSS0lORy5DTDETMBEGA1UEBRMKMTAwMzM3\nNDEtSzCCASIw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tq\nL74nIB0Cc545EXPmNx+IyYzfspu5UbwplbEH0IqOP84tGNnKRx9bq4oHGk2wENHH\nc/feGzdrVPgkQ6CVGFWQV39MJDoGDVgYrz7d3t3bAoGBAK+UnIFrRJ5UMsIM5Ao2\nryKtwPemdHypIVK3WOV1yRpa5aBqemrTQkijbLx8lVxoeID8Lw4zHybK6V9mAHsf\nRhfHsmBz3f4mYoKVoyVDelxpx+IGkGibvzNQB5BFWuu8kZeDPkhcPbk4pHFUf/jm\nCvLdtcSmumV5hxnVdtwjdlQD\n-----END PRIVATE KEY-----"}},"emisor":"76063822-6","resolucion":{"fecha":"2014-06-17","numero":57},"secuencia":1,"documentos":[{"TpoDoc":39,"NroDoc":3,"TasaImp":0,"FchDoc":"2021-07-05","MntExe":100,"MntNeto":0,"MntIVA":0,"MntTotal":100}]}
I mean in a json of one line BUT I need this kind of json:
{
"auth":{
"cert":{
"cert-data":"-",
"pkey-data":""
}
},
"emisor":"76063822-6",
"resolucion":{
"fecha":"2014-06-17",
"numero":57
},
"secuencia":1,
"documentos":[
{
"TpoDoc":39,
"NroDoc":3,
"TasaImp":0,
"FchDoc":"2021-07-05",
"MntExe":100,
"MntNeto":0,
"MntIVA":0,
"MntTotal":100
}
]
}
How you can see this json is not in one line I wonder how can I transform that lineal json to this kind of json if I am using json_encode?
Thanks
Just format it this way:
$data = json_encode($data, JSON_PRETTY_PRINT);
More info: https://www.php.net/manual/en/function.json-encode.php

how to use array_push() [duplicate]

This question already has answers here:
Add values to an associative array in PHP
(2 answers)
Closed 7 years ago.
I want to push new data in array which each value of them.
$array = array("menu1" => "101", "menu2" => "201");
array_push($array, "menu3" => "301");
But I got an error syntax.
And if I use like this :
$array = array("menu1" => "101", "menu2" => "201");
array_push($array, "menu3", "301");
result is : Array ( [menu1]=>101 [menu2]=>201 [0]=>menu3 [1]=>301 )
My hope the result is : Array ( [menu1]=>101 [menu2]=>201 [menu3]=>301 )
I want push new [menu3]=>'301' but I dont know how. Please help me, the answer will be appreciate
You can use
$array["menu3"] = "301"
as for array_push
array_push() treats array as a stack, and pushes the passed variables onto the end of array
so for associative arrays is a no match
another suitable function for what you want but it requires an array argument is array_merge
$result = array_merge(array("one" => "1"), array("two" => "2"));

Why is this PHP array not the same? [duplicate]

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 4 months ago.
I'm not understanding why the array:
<? $data = array( 'items[0][type]' => 'screenprint'); ?>
Is not the same as
<? echo $data['items'][0]['type']; ?>
I'm trying to add to the array but can't seem to figure out how?
array( 'items[0][type]' => 'screenprint')
This is an array which has one key which is named "items[0][type]" which has one value. That's not the same as an array which has a key items which has a key 0 which has a key type. PHP doesn't care that the key kinda looks like PHP syntax, it's just one string. What you want is:
$data = array('items' => array(0 => array('type' => 'screenprint')));
I hope it's obvious that that's a very different data structure.
It should be:
$data = [
'items' => [['type' => 'screenprint']]
];
echo $data['items'][0]['type'];

How to convert json objects into a PHP array [duplicate]

This question already has answers here:
How to convert JSON string to array
(17 answers)
Closed 8 years ago.
I want to be able to convert my JSON object into an array is there a built in function in php that allows me to do this?
Here is my json object:
in_userid: "38"
in_email: "user#email.com"
in_firstname: "John"
in_lastname: "Mason"
in_mobilenumber: "00000000000"
in_password: "pass12345"
in_phonenumber: "0000000"
and I want it to look something like this:
Array(
in_userid => "38",
in_email => "user#email.com",
in_firstname => "John",
in_lastname => "Mason",
in_mobilenumber => "00000000000",
in_password => "pass12345",
in_phonenumber => "0000000",
);
How will I do this?
use json_decode(). It takes a JSON encoded string and converts it into a PHP variable. See the json_decode function in the docs.

Convert a multidimensional array to an XML object in PHP [duplicate]

This question already has answers here:
How to convert array to SimpleXML
(34 answers)
Closed 8 years ago.
I have a multidimensional array like this:
$array = array(
"hello" => "hola",
"another_array" => array(
"key" => "best key ever",
"another" => "yes, another key",
),
"coolarray" => array(
"bool" => true,
"string" => "this is a string!",
),
);
I want a class like this:
class MyClass {
public $array;
public function __construct($array) {
// something
$this->array_to_xml($array);
}
public function array_to_xml($array) {
// convert array to xml
}
Then I want to be able to do things like this:
$string = $this->array->coolarray->string;
How can I do that?
This gets asked a lot
Not sure why you mention XML, sounds like you just want an object.
See this answer for example:
https://stackoverflow.com/a/11854285/543455
$obj = json_decode(json_encode($array));

Categories