[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-patch-tracker] [patch #9980] JSON encoder and decoder, alternati

From: anonymous
Subject: [Octave-patch-tracker] [patch #9980] JSON encoder and decoder, alternative to object2json
Date: Thu, 29 Oct 2020 11:19:22 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0

Follow-up Comment #24, patch #9980 (project octave):

On comment #21, my code was wrong to allow the '\"' pass thru as is, I fixed
that.   Turn's out my BIST for that check was wrong too.   I will upload

On the changing of "remote-settings/monitor_changes" to
"remote-settings_monitor_changes" (along with other fixings), I agree with you
and not that design choice.  Provided it doesn't cause "fromJSON" to exit in
error, I'm okay with "garbage in-garbage out" and leave it to the end user to
catch and fix as he/she sees fit.  The "invalid UTF-8" error, on the other
hand, bothers me.  Let me see what I can do.

On comment #19/20 vis a vis the ND array:

the difference is not a bug but difference in interpretation.  I  look (with
my own eyeballs) at the JSON string and see multiple pages of 2x2 matricies,
and "fromJSON" reflects that interpretation.  But it would seem jsondecode
sees it as pages of 2x4 matricies.

You can see the difference more clearly in a simpler example
(hypothetically-generated via "fromJSON_BIST.tst", you should check that
jsonA = '[[1, 2], [3, 4]]';
mat1A = jsondecode(jsonA); 
mat2A = fromJSON(jsonA);  

jsonB = '[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]';
mat1B = jsondecode(jsonB); 
mat2B = fromJSON(jsonB);  

returns the following.  One of these things is not like the others.

mat1A(:,:,1) => [1 2;3 4]    ## <-- inferred from "fromJSON_BIST.tst"
mat2A(:,:,1) => [1 2;3 4]    ## <-- actual

mat1B(:,:,1) => [1 3;5 7]    ## <-- inferred from "fromJSON_BIST.tst"
mat2B(:,:,1) => [1 2;3 4]    ## <-- actual

Which is correct: 'mat1B' or 'mat2B'? Actually, I don't know if this is really
a difference in interpretation or ND arrays hurts the brain of the original
"jsondecoder" developer too.  Either way, I prefer the output of "fromJSON", a
more intuitive flow from "jsonA" to "jsonB".    BTW, "object2json" sees it the
same as "jsonencode/jsondecode" and avoiding this was deliberate effort I

This brings me to a question.  At one time, I had the following BIST:

%! r = round(1000*rand(10,10,10,10,10));
%! assert(r, fromJSON( toJSON(r)));

but later took it out to avoid referring to an external function.  Can I put
it back in?

Again, I feel a JSON parser should try to work to mate Javascript to
Octave/Matlab, and Javascript only knows c-style, nested, 1-D arrays not
FORTRAN-style multidim arrays.    In this regards, "fromJSON" and "toJSON" do
not respect Octave column vectors: they treat any vector as a 1-D Javascript
row vector...ALWAYS.


Reply to this item at:


  Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]