Git Product home page Git Product logo

jsonio's Introduction

JSONio: a MATLAB/Octave JSON library

GitHub MATLAB Octave

JSONio is a MATLAB/Octave library to read/write data in the JSON (JavaScript Object Notation) data-interchange format.

It relies on the excellent JSON parser jsmn written by Serge Zaitsev:

INSTALLATION

Simply add the JSONio directory to the MATLAB path:

addpath /home/login/Documents/MATLAB/JSONio

A compiled MEX file is provided for 64-bit MATLAB platforms. It needs to be compiled for Octave with:

mkoctfile --mex jsonread.c jsmn.c -DJSMN_PARENT_LINKS

EXAMPLE

json = jsonread(filename)

jsonwrite(filename, json)

jsonio's People

Contributors

gllmflndn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jsonio's Issues

Issue on out of order array fields

Hi @gllmflndn,
reading a json with an array of objects with differently ordered fields gives this error:

>> jsonread(f)
Error using cell2mat (line 63)
The field names of each cell array element must be consistent and in consistent order.

An example to reproduce the error is the following:

[{
    "foo": "1", "bar": "2"
},
{
    "bar": "1", "foo": "3"
}]

Round trip on a JSON file with replacementStyle 'hex'

I just noticed the behavior below. At first it surprised me. But with some thought it might be the right behavior. If so, the perhaps this behavior could be explained in the header of the m-file a bit more.

%% Reading a '.' in an input JSON string.
%
% We use the opts argument to put a '.' in the output string.
%
clear srch
srch.subject0x2Eage= 1;    % Indicate we want a '.' in the JSON string
jsonwrite('test.json',srch,struct('replacementStyle','hex'))
type test.json                      % Looks good.

% Read the JSON file with replacement setting. It comes back with an underscore, not
% the hex field.  Hence, the write/read round-trip is not the identity.

test = jsonread('test.json',struct('replacementStyle','hex'));

% The returned struct does not have the hex code, but rather an underscore

test

Escaped characters in keys and values

Hi @gllmflndn! The following example (from our discussion at: incf-nidash/nidmresults-spm#40 (comment)):

>> json = containers.Map('nidm_DesignMatrix/prov:atLocation','./DesignMatrix.csv');
>> jsonwrite(json)

returns:

ans =
 {"nidm_DesignMatrix\/prov:atLocation":".\/DesignMatrix.csv"}

Is there any particular reason for the slashes to be escaped? I was hoping we could get:

{"nidm_DesignMatrix/prov:atLocation": "./DesignMatrix.csv"}

I am happy to investigate this and send a PR but I would like to make sure I understand when the escapes are needed.

Thank you in advance!

Errors on Tests with MATLAB R2020a

I have MATLAB R2020a on Windows 10.

This is what I get when running the tests:

>> runtests('test_jsonread')
Running test_jsonread
..
================================================================================
Error occurred in test_jsonread/test_jsonread_all_types and it did not run to completion.
    ---------
    Error ID:
    ---------
    'MATLAB:cell2mat:InconsistentFieldNames'
    --------------
    Error Details:
    --------------
    Error using cell2mat (line 63)
    The field names of each cell array element must be consistent and in consistent order.
    
    Error in test_jsonread>test_jsonread_all_types (line 127)
    act  = jsonread(json);
================================================================================
.
Done test_jsonread
__________

Failure Summary:

     Name                                   Failed  Incomplete  Reason(s)
    ======================================================================
     test_jsonread/test_jsonread_all_types    X         X       Errored.

ans = 

  1ร—3 TestResult array with properties:

    Name
    Passed
    Failed
    Incomplete
    Duration
    Details

Totals:
   2 Passed, 1 Failed (rerun), 1 Incomplete.
   0.053918 seconds testing time.

How to get started?

The README should contain information about how to get started. If I just use the addpath, I get the following error:

error: jsonread.c not compiled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.