Standard JSON format for PHP


Standard JSON format for PHP



I am storing data in JSON files with array of JSON objects.



Right Now I am doing like


[{"key1":"value1","key2":"value2"}]



Is this universally accepted. ? If so which Tech Lead company supports this format .





JSON is universal data format. So it is supported. In your case, however, json is incorrect as it uses single quotes. Correct json uses double quotes. More info on json.org.
– u_mulder
Jul 2 at 10:09






Okay ... let me correct that .. And thanks for opening the eyes of beginner
– Manjunath Jidagi
Jul 2 at 10:12




1 Answer
1



Do you have a reason for wrapping your main values in ? Are you intending to structure it as the following [{'key1':'value1','key2':'value2'.....},{'keyN':'valueN','keyN':'valueN'}.....] or similar? If not then using is pretty pointless.



[{'key1':'value1','key2':'value2'.....},{'keyN':'valueN','keyN':'valueN'}.....]






The reason is : I have read the file and store it in array and access each objects one by one ... Does it make sense here ???
– Manjunath Jidagi
Jul 2 at 10:11





So how I've described it then? If not then structuing it as - {'object1': {'key1':'value1','key2':'value2'}, 'object2' {'key1':'value1','key2':'value2'}} Would probably work better for you.
– Raffers
Jul 2 at 13:27



{'object1': {'key1':'value1','key2':'value2'}, 'object2' {'key1':'value1','key2':'value2'}}





If we follow this convention, is it possible to iterate over the objects. I think it's not possible @Raffers
– Manjunath Jidagi
Jul 4 at 9:01






Yes, it would be possible. You would first iterate over the array of the objects, then you would iterate over the values within the object. I assume you're passing to some JS?
– Raffers
Jul 5 at 11:24






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages