Tuesday, July 26, 2022

[FIXED] How to get json key as value instead string with json_encode function use

Issue

I am trying to convert php array to json using json_encode()

By using this I am getting [{"s":"simple2","value":"simple2","i":"img","u":"url","p":"520.000000"}]

Instead of key as string I wants this data in below format [{s:"simple2",value:"simple2",i:"img",u:"url",p:"520.000000"}]

How to get this type of data ? Is it possible to get this type data?


Solution

json_encode() will produce only a valid json format which is really the one it is producing. The one that you want is not a valid json format. You will have to apply text processing to get what you need. However, what is your final goal with the output of json array? Most languages that can can process json will accept the valid format.



Answered By - Mrigank Vallabh
Answer Checked By - Pedro (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.