dropbox / json11

A tiny JSON library for C++11.
MIT License
2.55k stars 613 forks source link

Can not modify Value when it's an array. #75

Closed Lunewcome closed 8 years ago

Lunewcome commented 8 years ago

The copy constructor in json11.h is like this : "const Value & operator[](size_t i) const" So user can not update an array by "[]", for example : obj["array"][0] = a_json_value; Why is it designed like this?

artwyman commented 8 years ago

The Json type is intended to be an immutable value type, which has a number of advantages including thread safety and the ability to share data across copies. If you want a mutable array you can use a Json::array (which is just a typedef for a vector) and mutate it freely before putting it into a Json object.