danieljimeneznz / tinyjson

A JSON CPP library for use in memory constraint environments. Originally Designed for the ATtiny841.
MIT License
0 stars 0 forks source link

Creating a JSON string by inserting k-v pairs causes an error when attempting to add a new k-v pair to a previously inserted parent. #7

Open danieljimeneznz opened 7 years ago

danieljimeneznz commented 7 years ago

Tested using initial JSON string: string = "{\"3\":{}}";

First inserting insert("spd", "{}", "3") <- This adds an extra opening bracket (and closing bracket).

Then inserting insert("req", "120", "3/spd"); <- This inserts correctly.

Then inserting insert("cur", "123", "3/spd"); <- This causes an issue with location sometimes becoming a very large number. 65135 (etc.)

danieljimeneznz commented 7 years ago

Still investigating. Currently if the key does not exist in the JSON string, it gets inserted correctly with the correct temp variable. Only issue is with the inserted variable now. (Need to seperate if value parameter is a {} or a [] from a "" variable to ensure unnecessary "" are not being added).

danieljimeneznz commented 7 years ago

Issue fixed to a point where it is usable. Only error currently occurs when an insert is attempted on a parent that does not contain a embedded JSON object,

e.g. insert("spd", "{}", "3") insert("req", "120", "3/spd"); Works fine.

but: insert("spd", "128", "3") insert("req", "120", "3/spd"); Will have issues.

Closing issue and will open a new one at a later date for the above bug.

danieljimeneznz commented 7 years ago

Thinking about it further, the above error is actually an illegal operation on a JSON string so a fix is not really required, but it would be good to have an error message or something. i.e. function returns a bool on whether insert was successful or not.