4 ms·
To be fair, MATLAB only added support for reading/writing JSON this very year. And they represent JSON objects as structs, which don't support all key names, an
by Derbasti 9y ago
To be fair, MATLAB only added support for reading/writing JSON this very year. And they represent JSON objects as structs, which don't support all key names, and they have a very "idiomatic" idea of which JSON arrays are decoded as matrices or cells, and how nested arrays sometimes result in nested arrays, and sometimes result in multi-dimensional arrays. And there's an uneasy relationship between the empty array and Null. It is kind of a mess, really.
- ansgri 9y agoI remember my colleague working with JSON in MATLAB via some thirdparty library about 2 or 3 years ago. It was regex-based, it was slow as hell but at least it was available.
- Derbasti 9y agoFun fact, I wrote my own JSON reader/writer in pure MATLAB, and it is also regex-based, and in many cases, it is faster than MATLAB's own, Mex-based JSON reader/writer: https://github.com/bastibe/transplant https://github.com/bastibe/transplant There are few things as slow as non-vectorized MATLAB code. MATLAB's regex engine is pretty decent, actually, and supports quite a few fancy tricks. For example, I use the regex engine to find the start/end of all numbers and strings ahead of time, and for replacing escape sequences (even unicode escapes!) with their literal characters. The former is particularly important because otherwise, you'd have to manually iterate over characters until you find the end of strings or numbers, which is unacceptably slow in MATLAB.
- radarsat1 9y agoAlso to be fair, although I can see some uses for supporting JSON in MATLAB, it makes a lot more sense if you're using an array language to use an array-oriented format such as HDF5, which has been supported in all the major numerical platforms for quite a while.
- sundarurfriend 9y ago> It is kind of a mess, really. Honestly, that statement applies to pretty much any part of MATLAB unless the behaviour is nailed down by existing mathematical or engineering specifications - and I'm talking as someone that likes MATLAB overall. Mathworks tries a bit to polish and paint it as a coherent whole, but it's patchwork of things built upon and stuck to the sides of the existing structure, optimizing towards a particular kind of "pragmatism" than towards any kind of elegance.