Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single map inside a list, list is not preserved #15

Closed
jpaasen opened this issue Dec 8, 2015 · 3 comments
Closed

Single map inside a list, list is not preserved #15

jpaasen opened this issue Dec 8, 2015 · 3 comments

Comments

@jpaasen
Copy link

jpaasen commented Dec 8, 2015

I have the following simple json-file that does not remain the same if you read it using loadjson and then store it with savejson (using the master branch and Matlab 2014b).

{
    "test1":[
        {
            "A":0,
            "B":1
        }
    ],
    "test2":{
        "C":2,
        "D":3
    }
}

The '[]' brackets are removed. I know that arrays with single elements is quite problematic in Matlab, but it looks like you now, compared to older versions, are able to create a cell-array holding a single struct. At least that is what I see printed in the console after loading the example file.

test = loadjson('test.json')
test = 
     test1 : {[1x1 struct]}
     test2 : [1x1 struct]

Would it be possible to use this information when storing the json file to preserve the single element list?

@cyrilpic
Copy link

👍
Having the same issue. An array with 1 element is not the same as the element directly.

Changing line 188 and 219 (replacing len > 1 by len > 0) does fix this in my case, but I am not well aware of possible side effects.

@jpaasen
Copy link
Author

jpaasen commented Dec 10, 2015

Thanks. It works for me as well.

Any chance to have the following file preserved after load-and-store?

{
    "test1":[0],
    "test2":1
}

@fangq
Copy link
Member

fangq commented Dec 11, 2015

Closed as a duplicate of issue #8. Please visit issue #8 for further discussions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants