Skip to content

loadjson: complex value was replaced by its conjugate #83

Description

@oldoldstone

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.';

Activity

  1. fangq commented on Aug 8, 2022

    @fangq
    Member

    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))
    
  2. added a commit that references this issue on Aug 21, 2024
    c729048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions