0

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 .

2
  • 3
    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. Commented Jul 2, 2018 at 10:09
  • Okay ... let me correct that .. And thanks for opening the eyes of beginner Commented Jul 2, 2018 at 10:12

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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 ???
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.
If we follow this convention, is it possible to iterate over the objects. I think it's not possible @Raffers
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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.