ArduinoJson: how to determine cause of parse error?

Greetings all. I'm doing a bit of IoT stuff involving a big JSON data blob that needs to be trimmed down to a subset than an Arduino can handle. So I've got a TCP server throwing JSON at me ("me" in this case is a process on a desktop computer) on an open port, and my eventual goal is to strip out the few bytes I am interested in (out of the 13K I'm receiving every 1 sec) and serve them in a compact, data-only, packed-string format via UDP to a listening Arduino.

Therefore I've been looking around for fairly lean, mean, easy to understand JSON libraries, and first came across JSMN (elegant and quick, works great, but very clunky/inefficient to search for data by kwd). Dissatisfied with this major flaw, I then tried ArduinoJSON. I thought that ArduinoJSON was the answer to my prayers because it is so easy to retrieve data by keyword. Seems like it should work fine on non-Arduino platforms. Got it to compile OK on my OSX devel host, But when I threw my 13+Kbyte JSON-filled char array at it (the same char array that JSMN parses correctly), it failed.

OK, I'm sure there's a reason... probably something I did wrong... but how do I find out what the reason is? It appears that the ArduinoJSON author provides only a boolean (success/failure) from the parse operation, whereas JSMN provides meaningful error codes on failure like "JSON incomplete," insufficient work buffer space" and so on.

If there are any ArduinoJSON users out there, can you tell me how to find out why a parse failed, rather than just that it failed? I did find this seemingly useful "troubleshooting" guide

which says that parsing can fail for 6 reasons, but then does not tell the reader how to determine which of the 6 reasons caused their particular failure!

What language do you use for your process on the desktop?

umm I'm taking that as, what am I writing the "man in the middle" daemon in? C++ using g++ compiler. no compile or link errors.

C is not my first language, so I'm not really qualified to "just go read the source" for ArduinoJSON alas... hence here begging for more expert advice.

arduinoJSON is designed to be portable so should not be an issue there

Have you submitted the JSON you actually receive (not the one you get by connecting from a browser or telnet to your service but exactly what your custom code is fetching) to an online parser (http://json.parser.online.fr or http://jsonviewer.stack.hu,... any other one) just to validate the issue is not in the buffer you try to parse?

Well, at 13Kbytes it's an awkward copy/paste prospect :slight_smile: but JSMN parses it without any trouble and it's parsing the exact same buffer that I'm handing to ArduinoJSON (I just spliced ArduinoJSON into the same client code) . So... I think the char array is valid JSON.

I'm thinking at this point of switching to "parson" anyway because I like its data retrieval notation better... so I may just give up on ArduinoJSON for now. who knew that shopping around for a "simple" JSON parser would become such a project!

For the moment I'm gonna give parson a test drive, and if that doesn't work I'll return to ArduinoJSON & try to figure it out. But thanks for the helpful hints!

UPDATE: yes. parson works perfectly, and is simpler to use than either JSMN or ArduinoJSON. I suspect it will not be appropriate for micro apps (needs a bit of memory), but is great on the desktop. parson worked on first tryout: parses my JSON char array without error, and offers pleasingly simple syntax for value extraction:

data = json_value_get_object(root_value);
printf("Data status: %s\n",json_object_dotget_string(data,"data.status"));
printf("Truck speed: %s\n",json_object_dotget_string(data,"data.telemetry.truck.speed"));
printf("Truck model: %s\n",json_object_dotget_string(data,"data.telemetry.truck.model"));

Sorry to bother y'all, I was wasting my time with ArduinoJSON. Parson is the right tool for this job.

If you have aman-in-the-middle, QUIT SENDING JSON. Extract JUST what you need, and send that.

@PaulS, yes in principle I agree. But in practise the JSON sender is (to me) a black box. I didn't write it, it came to me precompiled, and I wouldn't want to go anywhere near trying to reverse engineer it. So I just have to accept it as distro'd and make it work.