bugGNU Octave - Bugs: bug #39420, object2json doesn't support...


bug #39420: object2json doesn't support logical types

Submitted by:  None
Submitted on:  Sun 07 Jul 2013 04:07:04 PM UTC  
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  Philip Nienhuis <philipnienhuis>
Originator Name:  Keith Sheppard Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  other
Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 15 Aug 2013 08:16:50 PM UTC, comment #5:

Added changes to io-1.2.3 (uploaded to pkg release forum Aug. 15 2013). io-1.2.3 is meant for stable Octave (currently 3.6.4) and dev version < 3.7.2.
The test sections you made somehow have not been included there (sorry for that), inclusion of your patch was a last-minute addition.
Note that the last test in your git diff is incomplete (I saw that only after making the io-1.2.3 release). I've fixed that and committed to SVN (rev 12195).
The tests will be included in io-1.3.3 (meant for Octave 3.7.2+ dev version) that I'll put separately on the patch tracker later on.

I've amended the file header text to include a line on logical input arguments.

Thanks for your contribution!

Philip Nienhuis <philipnienhuis>
Project MemberIn charge of this item.
Mon 22 Jul 2013 04:17:53 AM UTC, comment #4:

OK I've added a couple of tests and checked them for validity with jsonlint.com. I would have run more test cases but it's pretty simple so I'm not sure what else would need to be tested.

diff --git a/object2json.m b/object2json.m
index f0bdb87..c44c2c7 100644
--- a/object2json.m
+++ b/object2json.m
@@ -98,6 +98,13 @@ function json = object2json (object)
object = replace_non_JSON_escapes (object);
json = [ '"', object, '"' ];

+ case 'logical'
+ if object
+ json = 'true';
+ else
+ json = 'false';
+ endif
% We don't know what is it so we'll put the class name
json = [ '"', class(object), '"' ];
@@ -187,3 +194,15 @@ function object = replace_non_JSON_escapes (object)
object = regexprep (object, '(?<!\\)\\(?=(\\\\)*(?!([\"\\\/bfnrt]|([u][0-9A-Fa-f]{4}))+?))', "\\\\");

+%! assert(object2json([logical(1), logical(0)]), '[true,false]');
+%! car.name = 'Mzd R8';
+%! car.speedsamples = [98, 33, 50; 56, 120, 102; 77, 82, 93];
+%! car.toofast = car.speedsamples >= 90;
+%! car.leased = logical(1);
+%! car.european = logical(0);
+%! assert(object2json(car), '{"name":"Mzd R8","speedsamples":[[98,33,50],[56,120,102],[77,82,93]],"toofast":[[true,false,false],[false,true,true],[false,false,true]],"le

Keith <keithshep>
Mon 08 Jul 2013 05:24:29 PM UTC, comment #3:

Just a script (or a transcript from Octave's terminal) would do - I'll add it to the object2json.m file (after consulting you if tit works OK).

OTOH, if you want, you can have a look at how tests are implemented in e.g., Octave's own .m files. Maybe you like it.
Just do e.g., "edit strread.m" and scroll to the bottom - you'll see a mix of examples.
To try tests, just do "test <functionname>.m"

Philip Nienhuis <philipnienhuis>
Project MemberIn charge of this item.
Mon 08 Jul 2013 12:55:41 PM UTC, comment #2:

Sure I can do that if it's simple. Do I just attach a script with a couple of examples showing that it works or is there more to it than that?

Keith <keithshep>
Sun 07 Jul 2013 09:21:30 PM UTC, comment #1:

Thanks for this.

Could you also provide a few tests, please? As my knowledge of JSON is negligible (I'm just io package maintainer) I have no idea if your code is valid for JSON output and really works OK.

If you can provide a few very simple test cases I could try to make a test section out of it.

(OS => Any)

Philip Nienhuis <philipnienhuis>
Project MemberIn charge of this item.
Sun 07 Jul 2013 04:07:04 PM UTC, original submission:

I added logical support to my local copy of object2json.m by adding the following case



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #28636:  object2json.m added by keithshep (7KiB - application/octet-stream - I messed up the comment formatting so here is the whole file if that helps.)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by keithshep (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-08-15 philipnienhuis StatusNone => Fixed
        Assigned toNone => philipnienhuis
        Open/ClosedOpen => Closed
    2013-07-22 keithshep Attached File- => Added object2json.m, #28636
    2013-07-07 philipnienhuis Operating SystemMac OS => Any

    Back to the top

    Powered by Savane 3.3