From 03133c72ab56a262814b9543cb8d7d693fa0edac Mon Sep 17 00:00:00 2001 From: Qianqian Fang <fangqq@gmail.com> Date: Tue, 1 Feb 2022 16:21:00 -0500 Subject: [PATCH] fix row-major ('formatversion',1.8) ND array storage order, update demo outputs --- examples/demo_jsonlab_basic.m | 2 +- examples/jsonlab_basictest.matlab | 552 ++++++++++++----------- examples/jsonlab_selftest.matlab | 116 ++--- examples/jsonlab_ubjson_basictest.matlab | 26 +- loadjson.m | 4 +- savejson.m | 15 +- test/run_jsonlab_test.m | 2 +- 7 files changed, 368 insertions(+), 349 deletions(-) diff --git a/examples/demo_jsonlab_basic.m b/examples/demo_jsonlab_basic.m index c4947a3..4ba6a1c 100644 --- a/examples/demo_jsonlab_basic.m +++ b/examples/demo_jsonlab_basic.m @@ -89,7 +89,7 @@ fprintf(1,'%%=================================================\n\n') data2json=reshape(1:(2*4*6),[2,4,6]); savejson('',data2json,'NestArray',1) -json2data=loadjson(ans,'fastarrayparser',0) +json2data=loadjson(ans) if(~isequaln(json2data,data2json)) warning('conversion does not preserve original data'); end diff --git a/examples/jsonlab_basictest.matlab b/examples/jsonlab_basictest.matlab index 7d8a4c4..072415c 100644 --- a/examples/jsonlab_basictest.matlab +++ b/examples/jsonlab_basictest.matlab @@ -68,7 +68,7 @@ data2json = ans = { - "emptystr": "" + "emptystr":"" } @@ -167,7 +167,7 @@ one"two ans = { - "str": "AB\tCD\none\"two" + "str":"AB\tCD\none\"two" } @@ -213,18 +213,18 @@ json2data = ans = [ - [ - [1,9,17,25,33,41], - [3,11,19,27,35,43], - [5,13,21,29,37,45], - [7,15,23,31,39,47] - ], - [ - [2,10,18,26,34,42], - [4,12,20,28,36,44], - [6,14,22,30,38,46], - [8,16,24,32,40,48] - ] + [ + [1,9,17,25,33,41], + [3,11,19,27,35,43], + [5,13,21,29,37,45], + [7,15,23,31,39,47] + ], + [ + [2,10,18,26,34,42], + [4,12,20,28,36,44], + [6,14,22,30,38,46], + [8,16,24,32,40,48] + ] ] @@ -273,9 +273,9 @@ json2data(:,:,6) = ans = { - "_ArrayType_": "double", - "_ArraySize_": [2,4,6], - "_ArrayData_": [1,9,17,25,33,41,3,11,19,27,35,43,5,13,21,29,37,45,7,15,23,31,39,47,2,10,18,26,34,42,4,12,20,28,36,44,6,14,22,30,38,46,8,16,24,32,40,48] + "_ArrayType_":"double", + "_ArraySize_":[2,4,6], + "_ArrayData_":[1,9,17,25,33,41,3,11,19,27,35,43,5,13,21,29,37,45,7,15,23,31,39,47,2,10,18,26,34,42,4,12,20,28,36,44,6,14,22,30,38,46,8,16,24,32,40,48] } @@ -324,9 +324,9 @@ json2data(:,:,6) = ans = { - "_ArrayType_": "double", - "_ArraySize_": [2,4,3,2], - "_ArrayData_": [1,25,9,33,17,41,3,27,11,35,19,43,5,29,13,37,21,45,7,31,15,39,23,47,2,26,10,34,18,42,4,28,12,36,20,44,6,30,14,38,22,46,8,32,16,40,24,48] + "_ArrayType_":"double", + "_ArraySize_":[2,4,3,2], + "_ArrayData_":[1,25,9,33,17,41,3,27,11,35,19,43,5,29,13,37,21,45,7,31,15,39,23,47,2,26,10,34,18,42,4,28,12,36,20,44,6,30,14,38,22,46,8,32,16,40,24,48] } @@ -375,42 +375,42 @@ json2data(:,:,3,2) = ans = [ - [ - [1,2], - [3,4], - [5,6], - [7,8] - ], - [ - [9,10], - [11,12], - [13,14], - [15,16] - ], - [ - [17,18], - [19,20], - [21,22], - [23,24] - ], - [ - [25,26], - [27,28], - [29,30], - [31,32] - ], - [ - [33,34], - [35,36], - [37,38], - [39,40] - ], - [ - [41,42], - [43,44], - [45,46], - [47,48] - ] + [ + [1,2], + [3,4], + [5,6], + [7,8] + ], + [ + [9,10], + [11,12], + [13,14], + [15,16] + ], + [ + [17,18], + [19,20], + [21,22], + [23,24] + ], + [ + [25,26], + [27,28], + [29,30], + [31,32] + ], + [ + [33,34], + [35,36], + [37,38], + [39,40] + ], + [ + [41,42], + [43,44], + [45,46], + [47,48] + ] ] @@ -459,9 +459,9 @@ json2data(:,:,6) = ans = { - "_ArrayType_": "double", - "_ArraySize_": [2,4,6], - "_ArrayData_": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48] + "_ArrayType_":"double", + "_ArraySize_":[2,4,6], + "_ArrayData_":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48] } @@ -515,10 +515,10 @@ data2json = ans = { - "_ArrayType_": "double", - "_ArraySize_": [1,1], - "_ArrayIsComplex_": true, - "_ArrayData_": [ + "_ArrayType_":"double", + "_ArraySize_":[1,1], + "_ArrayIsComplex_":true, + "_ArrayData_":[ [1], [2] ] @@ -549,10 +549,10 @@ data2json = ans = { - "_ArrayType_": "double", - "_ArraySize_": [6,3], - "_ArrayIsComplex_": true, - "_ArrayData_": [ + "_ArrayType_":"double", + "_ArraySize_":[6,3], + "_ArrayIsComplex_":true, + "_ArrayData_":[ [35,1,6,3,32,7,31,9,2,8,28,33,30,5,34,4,36,29], [26,19,24,21,23,25,22,27,20,17,10,15,12,14,16,13,18,11] ] @@ -583,7 +583,7 @@ data2json = ans = { - "specials": ["_NaN_","_Inf_","-_Inf_"] + "specials":["_NaN_","_Inf_","-_Inf_"] } @@ -614,11 +614,11 @@ data2json = ans = { - "sparse": { - "_ArrayType_": "double", - "_ArraySize_": [10,10], - "_ArrayIsSparse_": true, - "_ArrayData_": [ + "sparse":{ + "_ArrayType_":"double", + "_ArraySize_":[10,10], + "_ArrayIsSparse_":true, + "_ArrayData_":[ [1,9,3,10,10,7,2,6,10], [2,2,5,5,8,9,10,10,10], [0.655740699156586837,0.757740130578333448,0.849129305868777107,0.743132468124916179,0.392227019534168164,0.678735154857773471,0.0357116785741895537,0.933993247757550549,0.655477890177556644] @@ -655,12 +655,12 @@ data2json = ans = { - "complex_sparse": { - "_ArrayType_": "double", - "_ArraySize_": [10,10], - "_ArrayIsComplex_": true, - "_ArrayIsSparse_": true, - "_ArrayData_": [ + "complex_sparse":{ + "_ArrayType_":"double", + "_ArraySize_":[10,10], + "_ArrayIsComplex_":true, + "_ArrayIsSparse_":true, + "_ArrayData_":[ [2,1,1,7,8,9,4,1,3,10], [1,2,4,5,5,5,7,8,8,8], [0.655098003973840659,0.754686681982360885,0.276025076998578367,0.498364051982142953,0.959743958516081075,0.340385726666133204,0.118997681558376645,0.679702676853674803,0.162611735194630569,0.585267750979777346], @@ -684,11 +684,11 @@ json2data = ans = { - "all_zero_sparse": { - "_ArrayType_": "double", - "_ArraySize_": [2,3], - "_ArrayIsSparse_": true, - "_ArrayData_": [] + "all_zero_sparse":{ + "_ArrayType_":"double", + "_ArraySize_":[2,3], + "_ArrayIsSparse_":true, + "_ArrayData_":[] } } @@ -707,11 +707,11 @@ json2data = ans = { - "empty_sparse": { - "_ArrayType_": "double", - "_ArraySize_": [0,0], - "_ArrayIsSparse_": true, - "_ArrayData_": [] + "empty_sparse":{ + "_ArrayType_":"double", + "_ArraySize_":[0,0], + "_ArrayIsSparse_":true, + "_ArrayData_":[] } } @@ -730,7 +730,7 @@ json2data = ans = { - "empty_0by0_real": [] + "empty_0by0_real":[] } @@ -748,10 +748,10 @@ json2data = ans = { - "empty_0by3_real": { - "_ArrayType_": "double", - "_ArraySize_": [0,3], - "_ArrayData_": [] + "empty_0by3_real":{ + "_ArrayType_":"double", + "_ArraySize_":[0,3], + "_ArrayData_":[] } } @@ -770,11 +770,11 @@ json2data = ans = { - "sparse_column_vector": { - "_ArrayType_": "double", - "_ArraySize_": [5,1], - "_ArrayIsSparse_": true, - "_ArrayData_": [ + "sparse_column_vector":{ + "_ArrayType_":"double", + "_ArraySize_":[5,1], + "_ArrayIsSparse_":true, + "_ArrayData_":[ [2,4,5], [3,1,4] ] @@ -796,12 +796,12 @@ json2data = ans = { - "complex_sparse_column_vector": { - "_ArrayType_": "double", - "_ArraySize_": [5,1], - "_ArrayIsComplex_": true, - "_ArrayIsSparse_": true, - "_ArrayData_": [ + "complex_sparse_column_vector":{ + "_ArrayType_":"double", + "_ArraySize_":[5,1], + "_ArrayIsComplex_":true, + "_ArrayIsSparse_":true, + "_ArrayData_":[ [2,4,5], [3,1,4], [-3,-1,-4] @@ -824,11 +824,11 @@ json2data = ans = { - "sparse_row_vector": { - "_ArrayType_": "double", - "_ArraySize_": [1,5], - "_ArrayIsSparse_": true, - "_ArrayData_": [ + "sparse_row_vector":{ + "_ArrayType_":"double", + "_ArraySize_":[1,5], + "_ArrayIsSparse_":true, + "_ArrayData_":[ [2,4,5], [3,1,4] ] @@ -850,12 +850,12 @@ json2data = ans = { - "complex_sparse_row_vector": { - "_ArrayType_": "double", - "_ArraySize_": [1,5], - "_ArrayIsComplex_": true, - "_ArrayIsSparse_": true, - "_ArrayData_": [ + "complex_sparse_row_vector":{ + "_ArrayType_":"double", + "_ArraySize_":[1,5], + "_ArrayIsComplex_":true, + "_ArrayIsSparse_":true, + "_ArrayData_":[ [2,4,5], [3,1,4], [-3,-1,-4] @@ -887,18 +887,18 @@ data2json = ans = { - "astruct": { - "name": "Think Different", - "year": 1997, - "magic": [ + "astruct":{ + "name":"Think Different", + "year":1997, + "magic":[ [8,1,6], [3,5,7], [4,9,2] ], - "misfits": ["_Inf_","_NaN_"], - "embedded": { - "left": true, - "right": false + "misfits":["_Inf_","_NaN_"], + "embedded":{ + "left":true, + "right":false } } } @@ -923,18 +923,18 @@ logical ans = { - "Supreme Commander": [ + "Supreme Commander":[ { - "name": "Nexus Prime", - "rank": 9 + "name":"Nexus Prime", + "rank":9 }, { - "name": "Sentinel Prime", - "rank": 9 + "name":"Sentinel Prime", + "rank":9 }, { - "name": "Optimus Prime", - "rank": 9 + "name":"Optimus Prime", + "rank":9 } ] } @@ -943,7 +943,7 @@ ans = >> json2data = - Supreme_0x20_Commander: {[1x1 struct] [1x1 struct] [1x1 struct]} + Supreme_0x20_Commander: [1x3 struct] >> >> %================================================= @@ -961,31 +961,35 @@ data2json = ans = { - "debian": [ - [ - { - "buzz": 1.10, - "rex": 1.20, - "bo": 1.30, - "hamm": 2.00, - "slink": 2.10, - "potato": 2.20, - "woody": 3.00, - "sarge": 3.10, - "etch": 4.00, - "lenny": 5.00, - "squeeze": 6.00, - "wheezy": 7.00 - }, - { - "Ubuntu": [ - "Kubuntu", - "Xubuntu", - "Lubuntu" - ] - }, - [10.04,10.10,11.04,11.10] - ] + "debian":[ + [ + { + "buzz":1.10, + "rex":1.20, + "bo":1.30, + "hamm":2.00, + "slink":2.10, + "potato":2.20, + "woody":3.00, + "sarge":3.10, + "etch":4.00, + "lenny":5.00, + "squeeze":6.00, + "wheezy":7.00 + } + ], + [ + { + "Ubuntu":[ + "Kubuntu", + "Xubuntu", + "Lubuntu" + ] + } + ], + [ + [10.04,10.10,11.04,11.10] + ] ] } @@ -993,7 +997,7 @@ ans = >> json2data = - debian: {{1x3 cell}} + debian: {[1x1 struct] [1x1 struct] [10.0400 10.1000 11.0400 11.1000]} >> >> %================================================= @@ -1022,15 +1026,15 @@ data2json = ans = { - "handle": { - "function": "@(x)x+1", - "type": "anonymous", - "file": "", - "workspace": [ + "handle":{ + "function":"@(x)x+1", + "type":"anonymous", + "file":"", + "workspace":[ { } ], - "within_file_path": "__base_function" + "within_file_path":"__base_function" } } @@ -1049,35 +1053,35 @@ json2data = ans = { - "data2json": [ - [ + "data2json":[ [ - 1, [ - 2, - 3 + 1, + [ + 2, + 3 + ] + ], + [ + 4, + 5 + ], + [ + 6 ] ], [ - 4, - 5 - ], - [ - 6 - ] - ], - [ - [ - 7 - ], - [ - 8, - 9 - ], - [ - 10 + [ + 7 + ], + [ + 8, + 9 + ], + [ + 10 + ] ] - ] ] } @@ -1104,35 +1108,35 @@ data2json = ans = { - "data2json": [ + "data2json":[ [ { - "idx": 1, - "data": "structs" + "idx":1, + "data":"structs" }, { - "idx": 2, - "data": "structs" + "idx":2, + "data":"structs" } ], [ { - "idx": 3, - "data": "structs" + "idx":3, + "data":"structs" }, { - "idx": 4, - "data": "structs" + "idx":4, + "data":"structs" } ], [ { - "idx": 5, - "data": "structs" + "idx":5, + "data":"structs" }, { - "idx": 6, - "data": "structs" + "idx":6, + "data":"structs" } ] ] @@ -1142,7 +1146,7 @@ ans = >> json2data = - data2json: {{1x2 cell} {1x2 cell} {1x2 cell}} + data2json: [2x3 struct] >> >> >> %================================================= @@ -1159,26 +1163,26 @@ ans = [ { - "Format": "dd-MMM-uuuu", - "TimeZone": "", - "Year": 2015, - "Month": 4, - "Day": 8, - "Hour": 0, - "Minute": 0, - "Second": 0, - "SystemTimeZone": "America\/New_York" + "Format":"dd-MMM-uuuu", + "TimeZone":"", + "Year":2015, + "Month":4, + "Day":8, + "Hour":0, + "Minute":0, + "Second":0, + "SystemTimeZone":"America\/New_York" }, { - "Format": "dd-MMM-uuuu", - "TimeZone": "", - "Year": 2015, - "Month": 5, - "Day": 9, - "Hour": 0, - "Minute": 0, - "Second": 0, - "SystemTimeZone": "America\/New_York" + "Format":"dd-MMM-uuuu", + "TimeZone":"", + "Year":2015, + "Month":5, + "Day":9, + "Hour":0, + "Minute":0, + "Second":0, + "SystemTimeZone":"America\/New_York" } ] @@ -1186,7 +1190,17 @@ ans = json2data = - [1x1 struct] [1x1 struct] +1x2 struct array with fields: + + Format + TimeZone + Year + Month + Day + Hour + Minute + Second + SystemTimeZone >> >> %================================================= @@ -1206,9 +1220,9 @@ data2json = ans = { - "Andy": 21, - "Om": 22, - "William": 21 + "Andy":21, + "Om":22, + "William":21 } @@ -1238,25 +1252,25 @@ data2json = ans = { - "table": { - "_TableCols_": [ + "table":{ + "_TableCols_":[ "Names", "Age" ], - "_TableRows_": [], - "_TableRecords_": [ - [ - "Andy", - 21 - ], - [ - "William", - 21 - ], - [ - "Om", - 22 - ] + "_TableRows_":[], + "_TableRecords_":[ + [ + "Andy", + 21 + ], + [ + "William", + 21 + ], + [ + "Om", + 22 + ] ] } } @@ -1285,15 +1299,15 @@ data2json = ans = { - "_ArrayType_": "double", - "_ArraySize_": [5,8], - "_ArrayZipSize_": [6,5], - "_ArrayShape_": [ + "_ArrayType_":"double", + "_ArraySize_":[5,8], + "_ArrayZipSize_":[6,5], + "_ArrayShape_":[ "band", 2, 3 ], - "_ArrayData_": [11,17,23,29,35,6,12,18,24,30,1,7,13,19,25,0,2,8,14,20,0,0,3,9,15,0,0,0,4,10] + "_ArrayData_":[11,17,23,29,35,6,12,18,24,30,1,7,13,19,25,0,2,8,14,20,0,0,3,9,15,0,0,0,4,10] } @@ -1310,14 +1324,14 @@ json2data = ans = { - "_ArrayType_": "double", - "_ArraySize_": [5,8], - "_ArrayZipSize_": [4,5], - "_ArrayShape_": [ + "_ArrayType_":"double", + "_ArraySize_":[5,8], + "_ArrayZipSize_":[4,5], + "_ArrayShape_":[ "lowerband", 3 ], - "_ArrayData_": [1,7,13,19,25,0,2,8,14,20,0,0,3,9,15,0,0,0,4,10] + "_ArrayData_":[1,7,13,19,25,0,2,8,14,20,0,0,3,9,15,0,0,0,4,10] } @@ -1334,15 +1348,15 @@ json2data = ans = { - "_ArrayType_": "double", - "_ArraySize_": [5,8], - "_ArrayIsComplex_": true, - "_ArrayZipSize_": [2,3,5], - "_ArrayShape_": [ + "_ArrayType_":"double", + "_ArraySize_":[5,8], + "_ArrayIsComplex_":true, + "_ArrayZipSize_":[2,3,5], + "_ArrayShape_":[ "upperband", 2 ], - "_ArrayData_": [11,17,23,29,35,6,12,18,24,30,1,7,13,19,25,11,17,23,29,35,6,12,18,24,30,1,7,13,19,25] + "_ArrayData_":[11,17,23,29,35,6,12,18,24,30,1,7,13,19,25,11,17,23,29,35,6,12,18,24,30,1,7,13,19,25] } @@ -1369,10 +1383,10 @@ json2data = ans = { - "_ArrayType_": "int8", - "_ArraySize_": [5,8], - "_ArrayShape_": "diag", - "_ArrayData_": [1,7,13,19,25] + "_ArrayType_":"int8", + "_ArraySize_":[5,8], + "_ArrayShape_":"diag", + "_ArrayData_":[1,7,13,19,25] } @@ -1389,14 +1403,14 @@ json2data = ans = { - "_ArrayType_": "double", - "_ArraySize_": [5,5], - "_ArrayZipSize_": [4,5], - "_ArrayShape_": [ + "_ArrayType_":"double", + "_ArraySize_":[5,5], + "_ArrayZipSize_":[4,5], + "_ArrayShape_":[ "lowersymmband", 3 ], - "_ArrayData_": [2,14,26,38,50,0,8,20,32,44,0,0,14,26,38,0,0,0,4,10] + "_ArrayData_":[2,14,26,38,50,0,8,20,32,44,0,0,14,26,38,0,0,0,4,10] } @@ -1418,11 +1432,11 @@ json2data = ans = { - "_ArrayType_": "double", - "_ArraySize_": [20,10], - "_ArrayZipSize_": [1,200], - "_ArrayZipType_": "zlib", - "_ArrayZipData_": "eJxjYACBD/YMNAGj5o6aO2ruKBgFgwtQL10DAMHODQY= + "_ArrayType_":"double", + "_ArraySize_":[20,10], + "_ArrayZipSize_":[1,200], + "_ArrayZipType_":"zlib", + "_ArrayZipData_":"eJxjYACBD/YMNAGj5o6aO2ruKBgFgwtQL10DAMHODQY= " } diff --git a/examples/jsonlab_selftest.matlab b/examples/jsonlab_selftest.matlab index ba84d9d..5a0d577 100644 --- a/examples/jsonlab_selftest.matlab +++ b/examples/jsonlab_selftest.matlab @@ -14,54 +14,54 @@ For product information, visit www.mathworks.com. >> >> >> >> >> =============================================== >> example1.json { - "data": { - "firstName": "John", - "lastName": "Smith", - "age": 25, - "address": { - "streetAddress": "21 2nd Street", - "city": "New York", - "state": "NY", - "postalCode": "10021" + "data":{ + "firstName":"John", + "lastName":"Smith", + "age":25, + "address":{ + "streetAddress":"21 2nd Street", + "city":"New York", + "state":"NY", + "postalCode":"10021" }, - "phoneNumber": [ + "phoneNumber":[ { - "type": "home", - "number": "212 555-1234" + "type":"home", + "number":"212 555-1234" }, { - "type": "fax", - "number": "646 555-4567" + "type":"fax", + "number":"646 555-4567" } ] } } -{"data": {"firstName": "John","lastName": "Smith","age": 25,"address": {"streetAddress": "21 2nd Street","city": "New York","state": "NY","postalCode": "10021"},"phoneNumber": [{"type": "home","number": "212 555-1234"},{"type": "fax","number": "646 555-4567"}]}} +{"data":{"firstName":"John","lastName":"Smith","age":25,"address":{"streetAddress":"21 2nd Street","city":"New York","state":"NY","postalCode":"10021"},"phoneNumber":[{"type":"home","number":"212 555-1234"},{"type":"fax","number":"646 555-4567"}]}} =============================================== >> example2.json { - "data": { - "glossary": { - "title": "example glossary", - "GlossDiv": { - "title": "S", - "GlossList": { - "GlossEntry": { - "ID": "SGML", - "SortAs": "SGML", - "GlossTerm": "Standard Generalized Markup Language", - "Acronym": "SGML", - "Abbrev": "ISO 8879:1986", - "GlossDef": { - "para": "A meta-markup language, used to create markup languages such as DocBook.", - "GlossSeeAlso": [ + "data":{ + "glossary":{ + "title":"example glossary", + "GlossDiv":{ + "title":"S", + "GlossList":{ + "GlossEntry":{ + "ID":"SGML", + "SortAs":"SGML", + "GlossTerm":"Standard Generalized Markup Language", + "Acronym":"SGML", + "Abbrev":"ISO 8879:1986", + "GlossDef":{ + "para":"A meta-markup language, used to create markup languages such as DocBook.", + "GlossSeeAlso":[ "GML", "XML" ] }, - "GlossSee": "markup" + "GlossSee":"markup" } } } @@ -69,28 +69,28 @@ For product information, visit www.mathworks.com. } } -{"data": {"glossary": {"title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": {"ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": {"para": "A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso": ["GML","XML"]},"GlossSee": "markup"}}}}}} +{"data":{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}} =============================================== >> example3.json { - "data": { - "menu": { - "id": "file", - "value": "_&File", - "popup": { - "menuitem": [ + "data":{ + "menu":{ + "id":"file", + "value":"_&File", + "popup":{ + "menuitem":[ { - "value": "_&New", - "onclick": "CreateNewDoc(\"'\\\"Untitled\\\"'\")" + "value":"_&New", + "onclick":"CreateNewDoc(\"'\\\"Untitled\\\"'\")" }, { - "value": "_&Open", - "onclick": "OpenDoc()" + "value":"_&Open", + "onclick":"OpenDoc()" }, { - "value": "_&Close", - "onclick": "CloseDoc()" + "value":"_&Close", + "onclick":"CloseDoc()" } ] } @@ -98,26 +98,32 @@ For product information, visit www.mathworks.com. } } -{"data": {"menu": {"id": "file","value": "_&File","popup": {"menuitem": [{"value": "_&New","onclick": "CreateNewDoc(\"'\\\"Untitled\\\"'\")"},{"value": "_&Open","onclick": "OpenDoc()"},{"value": "_&Close","onclick": "CloseDoc()"}]}}}} +{"data":{"menu":{"id":"file","value":"_&File","popup":{"menuitem":[{"value":"_&New","onclick":"CreateNewDoc(\"'\\\"Untitled\\\"'\")"},{"value":"_&Open","onclick":"OpenDoc()"},{"value":"_&Close","onclick":"CloseDoc()"}]}}}} =============================================== >> example4.json { - "data": [ + "data":[ { - "sample": { - "rho": 1 + "sample":{ + "rho":1 } }, { - "sample": { - "rho": 2 + "sample":{ + "rho":2 } }, [ - [1,0], - [1,1], - [1,2] + [ + [1,0] + ], + [ + [1,1] + ], + [ + [1,2] + ] ], [ "Paper", @@ -137,7 +143,7 @@ For product information, visit www.mathworks.com. ] } -{"data": [{"sample": {"rho": 1}},{"sample": {"rho": 2}},[[1,0],[1,1],[1,2]],["Paper","Scissors","Stone"],["a","b\\","c\"","d\\\"","e\"[","f\\\"[","g[\\","h[\\\""]]} +{"data":[{"sample":{"rho":1}},{"sample":{"rho":2}},[[[1,0]],[[1,1]],[[1,2]]],["Paper","Scissors","Stone"],["a","b\\","c\"","d\\\"","e\"[","f\\\"[","g[\\","h[\\\""]]} >> >> =============================================== >> example1.json @@ -153,5 +159,5 @@ GlossEntry{UIDSUSGMLUSortAsSUSGMLU GlossTermSU$Standard Generalized Markup L CloseDoc()}]}}}} =============================================== >> example4.json -{Udata[{Usample{UrhoU}}{Usample{UrhoU}}[[$U#U [$U#U[$U#U][SUPaperSUScissorsSUStone][CaSUb\SUc"SUd\"SUe"[SUf\"[SUg[\SUh[\"]]} +{Udata[{Usample{UrhoU}}{Usample{UrhoU}}[[[$U#U [$U#U[$U#U]][SUPaperSUScissorsSUStone][CaSUb\SUc"SUd\"SUe"[SUf\"[SUg[\SUh[\"]]} >> \ No newline at end of file diff --git a/examples/jsonlab_ubjson_basictest.matlab b/examples/jsonlab_ubjson_basictest.matlab index d3544a4..4ba3c44 100644 --- a/examples/jsonlab_ubjson_basictest.matlab +++ b/examples/jsonlab_ubjson_basictest.matlab @@ -24,7 +24,7 @@ data2json = >> ans = -[D@ !ûTD-] +D-DTû! @ >> json2data = @@ -380,8 +380,8 @@ data2json = >> ans = -{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsComplex_TU_ArrayData_[$U#[$U#U# -!" $} +{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsComplex_TU_ArrayData_[$U#[$U#U# !"$ + } >> json2data = @@ -406,7 +406,7 @@ data2json = >> ans = -{Uspecials[$D#Uÿø ð ÿð } +{Uspecials[$D#U øÿ ð ðÿ} >> json2data = @@ -436,7 +436,7 @@ ans = {Usparse{U_ArrayType_SUdoubleU_ArraySize_[$U#U -U_ArrayIsSparse_TU_ArrayData_[$D#[$U#U ?ð @ ?äûÓë12@" @ ?è?h:öl;@ @ ?ë,8Ù±@$ @ ?çǽ½æ'#@$ @ ?Ù?[`o@ @" ?å¸2ÉNé@ @$ ?¢HÍpà@ @$ ?íãEι¶P@$ @$ ?äù¬Ä² ¶}} +U_ArrayIsSparse_TU_ArrayData_[$D#[$U#U ð? "@ @ $@ $@ @ @ @ $@ @ @ @ @ @ "@ $@ $@ $@21ëÓûä?;lö:h?è?±Ù8,ë?#'æ½½Çç?o`[?Ù?éNÉ2¸å?àpÍH¢?P¶¹ÎEãí?¶ ²Ä¬ùä?}} >> json2data = @@ -466,7 +466,7 @@ ans = {Ucomplex_sparse{U_ArrayType_SUdoubleU_ArraySize_[$U#U -U_ArrayIsComplex_TU_ArrayIsSparse_TU_ArrayData_[$D#[$U#U ?ð @ ?äûÓë12¿äûÓë12@" @ ?è?h:öl;¿è?h:öl;@ @ ?ë,8Ù±¿ë,8Ù±@$ @ ?çǽ½æ'#¿çǽ½æ'#@$ @ ?Ù?[`o¿Ù?[`o@ @" ?å¸2ÉNé¿å¸2ÉNé@ @$ ?¢HÍpà¿¢HÍpà@ @$ ?íãEι¶P¿íãEι¶P@$ @$ ?äù¬Ä² ¶¿äù¬Ä² ¶}} +U_ArrayIsComplex_TU_ArrayIsSparse_TU_ArrayData_[$D#[$U#U ð? "@ @ $@ $@ @ @ @ $@ @ @ @ @ @ "@ $@ $@ $@21ëÓûä?;lö:h?è?±Ù8,ë?#'æ½½Çç?o`[?Ù?éNÉ2¸å?àpÍH¢?P¶¹ÎEãí?¶ ²Ä¬ùä?21ëÓûä¿;lö:h?迱Ù8,ë¿#'æ½½Çç¿o`[?Ù¿éNÉ2¸å¿àpÍH¢¿P¶¹ÎEãí¿¶ ²Ä¬ùä¿}} >> json2data = @@ -541,7 +541,7 @@ json2data = >> >> >> ans = -{Usparse_column_vector{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsSparse_TU_ArrayData_[$U#[$U#U}} +{Usparse_column_vector{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsSparse_TU_ArrayData_[$U#[$U#U}} >> json2data = @@ -556,7 +556,7 @@ json2data = >> >> >> ans = -{Ucomplex_sparse_column_vector{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsComplex_TU_ArrayIsSparse_TU_ArrayData_[$i#[$U#Uýÿü}} +{Ucomplex_sparse_column_vector{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsComplex_TU_ArrayIsSparse_TU_ArrayData_[$i#[$U#Uýÿü}} >> json2data = @@ -571,7 +571,7 @@ json2data = >> >> >> ans = -{Usparse_row_vector{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsSparse_TU_ArrayData_[$U#[$U#U}} +{Usparse_row_vector{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsSparse_TU_ArrayData_[$U#[$U#U}} >> json2data = @@ -586,7 +586,7 @@ json2data = >> >> >> ans = -{Ucomplex_sparse_row_vector{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsComplex_TU_ArrayIsSparse_TU_ArrayData_[$i#[$U#Uýÿü}} +{Ucomplex_sparse_row_vector{U_ArrayType_SUdoubleU_ArraySize_[$U#UU_ArrayIsComplex_TU_ArrayIsSparse_TU_ArrayData_[$i#[$U#Uýÿü}} >> json2data = @@ -610,7 +610,7 @@ data2json = >> ans = -{Uastruct{UnameSUThink DifferentUyearuÍUmagic[$U#[$U#U Umisfits[$D#Uð ÿø Uembedded{UleftTUrightF}}} +{Uastruct{UnameSUThink DifferentUyearuÍUmagic[$U#[$U#U Umisfits[$D#U ð øÿUembedded{UleftTUrightF}}} >> json2data = @@ -652,7 +652,7 @@ data2json = >> ans = -{Udebian[[{Ubuzz[D?ñ]Urex[D?ó333333]Ubo[D?ôÌÌÌÌÌÍ]UhammUUslink[D@ ÌÌÌÌÌÍ]Upotato[D@]UwoodyUUsarge[D@ÌÌÌÌÌÍ]UetchUUlennyUUsqueezeUUwheezyU}{UUbuntu[SUKubuntuSUXubuntuSULubuntu]}[$D#U@$záG®@$333333@&záG®@&333333]]} +{Udebian[[{UbuzzDñ?UrexD333333ó?UboDÍÌÌÌÌÌô?UhammUUslinkDÍÌÌÌÌÌ @UpotatoD@UwoodyUUsargeDÍÌÌÌÌÌ@UetchUUlennyUUsqueezeUUwheezyU}{UUbuntu[SUKubuntuSUXubuntuSULubuntu]}[$D#U®Gáz$@333333$@®Gáz&@333333&@]]} >> json2data = @@ -744,7 +744,7 @@ data2json = ans = -[{UFormatSUdd-MMM-uuuuUTimeZoneSU UYearußUMonthUUDayUUHourU UMinuteU USecondU USystemTimeZoneSUAmerica/New_York}{UFormatSUdd-MMM-uuuuUTimeZoneSU UYearußUMonthUUDayU UHourU UMinuteU USecondU USystemTimeZoneSUAmerica/New_York}] +[{UFormatSUdd-MMM-uuuuUTimeZoneSU UYearußUMonthUUDayUUHourU UMinuteU USecondU USystemTimeZoneSUAmerica/New_York}{UFormatSUdd-MMM-uuuuUTimeZoneSU UYearußUMonthUUDayU UHourU UMinuteU USecondU USystemTimeZoneSUAmerica/New_York}] json2data = diff --git a/loadjson.m b/loadjson.m index 51e3df6..42b42f5 100644 --- a/loadjson.m +++ b/loadjson.m @@ -48,7 +48,7 @@ function data = loadjson(fname,varargin) % ParseStringArray [0|1]: if set to 0, loadjson converts "string arrays" % (introduced in MATLAB R2016b) to char arrays; if set to 1, % loadjson skips this conversion. -% FormatVersion [2|float]: set the JSONLab format version; since +% FormatVersion [3|float]: set the JSONLab format version; since % v2.0, JSONLab uses JData specification Draft 1 % for output format, it is incompatible with all % previous releases; if old output is desired, @@ -131,7 +131,7 @@ function data = loadjson(fname,varargin) opt.arraytokenidx_=arraytokenidx; opt.simplifycell=jsonopt('SimplifyCell',1,opt); opt.simplifycellarray=jsonopt('SimplifyCellArray',opt.simplifycell,opt); - opt.formatversion=jsonopt('FormatVersion',2,opt); + opt.formatversion=jsonopt('FormatVersion',3,opt); opt.fastarrayparser=jsonopt('FastArrayParser',1,opt); opt.parsestringarray=jsonopt('ParseStringArray',0,opt); opt.usemap=jsonopt('UseMap',0,opt); diff --git a/savejson.m b/savejson.m index 04f752b..2bf4098 100644 --- a/savejson.m +++ b/savejson.m @@ -90,7 +90,7 @@ function json=savejson(rootname,obj,varargin) % element count is larger than this number. % CompressStringSize [400|int]: only to compress a string if the total % element count is larger than this number. -% FormatVersion [2|float]: set the JSONLab output version; since +% FormatVersion [3|float]: set the JSONLab output version; since % v2.0, JSONLab uses JData specification Draft 1 % for output format, it is incompatible with all % previous releases; if old output is desired, @@ -148,7 +148,7 @@ opt.nestarray=jsonopt('NestArray',0,opt); opt.compact=jsonopt('Compact',0,opt); opt.singletcell=jsonopt('SingletCell',1,opt); opt.singletarray=jsonopt('SingletArray',0,opt); -opt.formatversion=jsonopt('FormatVersion',2,opt); +opt.formatversion=jsonopt('FormatVersion',3,opt); opt.compressarraysize=jsonopt('CompressArraySize',100,opt); opt.compressstringsize=jsonopt('CompressStringSize',opt.compressarraysize*4,opt); opt.intformat=jsonopt('IntFormat','%.0f',opt); @@ -315,17 +315,16 @@ end isnum2cell=varargin{1}.num2cell_; if(isnum2cell) item=squeeze(item); - format=varargin{1}.formatversion; - if(format>1.9 && ~isvector(item)) + if(~isvector(item)) item=permute(item,ndims(item):-1:1); end end dim=size(item); -if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now - item=reshape(item,dim(1),numel(item)/dim(1)); - dim=size(item); -end +% if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now +% item=reshape(item,dim(1),numel(item)/dim(1)); +% dim=size(item); +% end len=numel(item); ws=varargin{1}.whitespaces_; padding0=repmat(ws.tab,1,level); diff --git a/test/run_jsonlab_test.m b/test/run_jsonlab_test.m index a894934..0c68b95 100644 --- a/test/run_jsonlab_test.m +++ b/test/run_jsonlab_test.m @@ -63,7 +63,7 @@ if(ismember('js',tests)) test_jsonlab('3d (row-major) nested array',@savejson,reshape(1:(2*3*2),2,3,2),... '[[[1,7],[3,9],[5,11]],[[2,8],[4,10],[6,12]]]','compact',1,'nestarray',1); test_jsonlab('3d (column-major) nested array',@savejson,reshape(1:(2*3*2),2,3,2),... - '[[[1,2],[7,8]],[[3,4],[9,10]],[[5,6],[11,12]]]','compact',1,'nestarray',1,'formatversion',1.9); + '[[[1,2],[3,4],[5,6]],[[7,8],[9,10],[11,12]]]','compact',1,'nestarray',1,'formatversion',1.9); test_jsonlab('3d annotated array',@savejson,reshape(int8(1:(2*3*2)),2,3,2),... '{"_ArrayType_":"int8","_ArraySize_":[2,3,2],"_ArrayData_":[1,7,3,9,5,11,2,8,4,10,6,12]}','compact',1); test_jsonlab('complex number',@savejson,single(2+4i),... -- GitLab