kyamagu / matlab-json

Use official API: https://mathworks.com/help/matlab/json-format.html
Other
52 stars 15 forks source link

Non-reversible parsing #7

Closed sheljohn closed 8 years ago

sheljohn commented 8 years ago

I would expect the following JSON:

{
    "bar": [
        [1],
        [2],
        [3]
    ]
}

to be parsed as struct('bar',{1,2,3}) (or a cell column), but instead it gets parsed as struct('bar',[1;2;3]).

kyamagu commented 8 years ago

@Sheljohn There is MergeCell option that changes the behavior. See function help.

sheljohn commented 8 years ago

Setting MergeCell to false yields struct('bar',{{1},{2},{3}}), which is still not the desired output.

kyamagu commented 8 years ago

@Sheljohn Then implement your own parsing rule. Matlab treats everything as an array, and there is always an ambiguity in parse rule. See README.

sheljohn commented 8 years ago

That is simply wrong, there is no ambiguity when it comes to parsing either cells or arrays, the only missing information in JSON is about the shape of the containers.

kyamagu commented 8 years ago

@Sheljohn Yes, but embedding shape information is not possible with the current JSON spec, unless preparing the shape field in every object.

sheljohn commented 8 years ago

You missed the point of the issue I think; I have no problem with the shape of the output, it is the type that is wrong.

kyamagu commented 8 years ago

@Sheljohn See README for the current conversion rule. It is impossible to distinguish a numeric array from cell arrays in the JSON spec. Perhaps you can customize the parser implementation for your own purpose.

sheljohn commented 8 years ago

It is impossible to distinguish a numeric array from cell arrays in the JSON spec.

This is wrong. You should probably realise that valid arrays of arrays in Matlab are always arrays, and therefore arrays of arrays in JSON can be used to represent cells without ambiguity.

kyamagu commented 8 years ago

@Sheljohn This parser implementation is designed primarily for N-D array usage, and that's why the parsing rule is defined in the following way (from README). MergeCell option controls this behavior. If you need something else, you are free to hack the implementation.

sheljohn commented 8 years ago

Right. Saying that there is no full and reversible mapping between JSON and Matlab is wrong though, so these claims should probably be removed from the README. I will stop bothering you with this bug as you seem to have no intention of fixing it, and because I think it was your intent to settle for a partial non-reversible mapping. Apologies for the trouble