note 125324 added to function.json-encode

From: Date: Thu, 03 Sep 2020 22:40:10 +0000
Subject: note 125324 added to function.json-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-215066@lists.php.net to get a copy of this message
Currently I'm using PHP 7.4 If i decode a json string with two objects inside: Array ( [0] => stdClass Object ( [userId] => 6 [userName] => Ruben Elizondo [subscribedOn] => 2020-09-03 16:10:04 ) [1] => stdClass Object ( [userId] => 1 [userName] => Ruben Elizondo updated again [subscribedOn] => 2020-09-03 16:10:43 ) ) if i json_encode them i get: [{"userId":6,"userName":"Ruben Elizondo","subscribedOn":"2020-09-03 16:10:04"},{"userId":1,"userName":"Ruben Elizondo updated again","subscribedOn":"2020-09-03 16:10:43"}] which is fine, now from the original array i remove one element to get: Array ( [1] => stdClass Object ( [userId] => 1 [userName] => Ruben Elizondo updated again [subscribedOn] => 2020-09-03 16:10:43 ) ) and if i json_encode this i get: {"1":{"userId":1,"userName":"Ruben Elizondo updated again","subscribedOn":"2020-09-03 16:10:43"}} so for arrays with 2 or more objects i get encoded a string that is a json representation of an array of objects, but if i have only 1 element, the json encoded string is an object inside another object That's a big issue for my use case. ---- Server IP: 45.112.84.4 Probable Submitter: 195.138.250.34 (proxied: 2605:e000:121d:cba5:1cfd:8e1e:e7c1:e798) ---- Manual Page -- http://php.net/manual/en/function.json-encode.php Edit -- https://master.php.net/note/edit/125324 Del: integrated -- https://master.php.net/note/delete/125324/integrated Del: useless -- https://master.php.net/note/delete/125324/useless Del: bad code -- https://master.php.net/note/delete/125324/bad+code Del: spam -- https://master.php.net/note/delete/125324/spam Del: non-english -- https://master.php.net/note/delete/125324/non-english Del: in docs -- https://master.php.net/note/delete/125324/in+docs Del: other reasons-- https://master.php.net/note/delete/125324 Reject -- https://master.php.net/note/reject/125324 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215066) next »