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

loadjson: complex value was replaced by its conjugate #83

Closed
oldoldstone opened this issue Aug 8, 2022 · 1 comment
Closed

loadjson: complex value was replaced by its conjugate #83

oldoldstone opened this issue Aug 8, 2022 · 1 comment

Comments

@oldoldstone
Copy link

example

>> dat=loadjson('{"array":[1,2,3-4i]}')
dat = 
  array: [1.0000 + 0.0000i 2.0000 + 0.0000i 3.0000 + 4.0000i]

maybe caused by this code

loadjson.m, row 410
if(~iscell(object) && size(object,1)>1 && ndims(object)==2)
   object=object';
end

should be
object=object.';

@fangq fangq closed this as completed in c729048 Aug 8, 2022
@fangq
Copy link
Member

fangq commented Aug 8, 2022

interesting finding .. thanks, it is now fixed.

I want to mention that {"array":[1,2,3-4i]} is not a valid JSON string because JSON does not support complex numbers, but using the default FastArrayParser, this is acceptable to loadjson and can be parsed. Disabling it will give an error

loadjson('{"array":[1,2,3-4i]}','fastarrayparser',0)

A more unambiguous (and JSON compatible) way to handle complex number is to use the built-in JData annotation:

array=[1,2,3-4i];
savejson(array)
loadjson(savejson(array))

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

2 participants