FastLED 3.10.8
Loading...
Searching...
No Matches

◆ operator[]() [2/4]

json fl::json::operator[] ( const fl::string & key)
inline

Definition at line 752 of file json.h.

754 {
755 if (!mValue || !mValue->is_object()) {
757 }
758 // FastLED#3588: make_shared may degrade to empty under OOM.
759 if (!mValue) { return json(nullptr); }
760 // Get reference to the json_value
761 auto objPtr = mValue->data.ptr<json_object>();
762 if (objPtr) {
763 // If key doesn't exist, create a new json_value and insert it
764 if (objPtr->find(key) == objPtr->end()) {
765 (*objPtr)[key] = fl::make_shared<json_value>(nullptr);
766 }
767 // Return a new json object that wraps the shared_ptr to the json_value
768 return json((*objPtr)[key]);
769 }
770 // Should not happen if mValue is properly initialized as an object
771 //return *reinterpret_cast<json*>(&get_null_value());
fl::shared_ptr< json_value > mValue
Definition json.h:263
json() FL_NO_EXCEPT
Definition json.h:267
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
fl::flat_map< fl::string, fl::shared_ptr< json_value >, fl::StringFastLess > json_object
Definition types.h:55