octave-patch-tracker
[Top][All Lists]
Advanced

[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: Sat, 24 Oct 2020 11:54:58 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0

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

I've uploaded a new version.  Aside from adding suggested testing
improvements, it they worker harder at mating native JSON/Javascript objects
with native Octave objects, namely ND arrays and struct arrays. 

fromJSON
========

Per comments, some more input checking and BIST has been added.  Pointing to
exact character position could be VERY helpful, but 'fromJSON' works
recursively, start with big blocks of string and working down to smaller
fragments.  As such, error position is a "nice to have".  Instead, 'fromJSON'
cites relevant fragments when malformed JSON is found.  

toJSON
======

Per comments, more input checking and BIST have been added/fixed.  On exotics
like java or COM, the norm for stringifying non-(number,bool,string) is a
placeholder with a quoted-string of its class name (e.g. '"[SomeClass]"'),
which 'toJSON' observes. Provided that 'class()' works on any Octave object,
there are no "invalid" inputs, just unfullfilling outputs.  I've added a BIST
test with java object for verification.

On other input tests, i.e. PREC and COMPACT (formerly JSON), done. 

The input checking statement


isbool(PREC) && ([PREC,JSON] = {[],PREC}{}); 


is my preferred contraction for:


if isbool(PREC); 
    JSON = PREC;
    PREC = [];
endif


The resulting bool value in irrelavent.  I understand comment about being
complicated.

Regarding compatibility, 'toJSON' and 'fromJSON' is made to work with
Javscript's primative objects and its built-in parser ('JSON.parse' and
'JSON.stringify').  With all due respect, that is the standard to which any
JSON parser should rise.  If 'jsondecode' plays nicely with Javascript, then
'toJSON' should work with 'jsondecode'.

(file #50087, file #50088)
    _______________________________________________________

Additional Item Attachment:

File name: fromJSON_v2.m                  Size:17 KB
    <https://file.savannah.gnu.org/file/fromJSON_v2.m?file_id=50087>

File name: toJSON_v2.m                    Size:13 KB
    <https://file.savannah.gnu.org/file/toJSON_v2.m?file_id=50088>



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/patch/?9980>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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