| 891 | } |
| 892 | |
| 893 | void push_value(const fl::shared_ptr<json_value>& val) { |
| 894 | if (mStack.empty()) { |
| 895 | mRoot = val; |
| 896 | } else { |
| 897 | StackFrame& top = mStack.back(); |
| 898 | |
| 899 | if (top.type == StackFrame::OBJECT) { |
| 900 | // Attach to object with pending key |
| 901 | auto obj = top.value->data.ptr<json_object>(); |
| 902 | if (obj && !top.pending_key.empty()) { |
| 903 | (*obj)[top.pending_key] = val; |
| 904 | top.pending_key.clear(); |
| 905 | } |
| 906 | } else { |
| 907 | // Attach to array |
| 908 | auto arr = top.value->data.ptr<json_array>(); |
| 909 | if (arr) { |
| 910 | arr->push_back(val); |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | public: |
| 917 | JsonBuilder() FL_NOEXCEPT : mRoot(), mDepth(0) {} |