Giter Club home page Giter Club logo

mruby-json's Introduction

mruby-json

Build Status

JSON parser for mruby

install by mrbgems

MRuby::Build.new do |conf|

    # ... (snip) ...

    conf.gem :github => 'mattn/mruby-json'
end

License

MIT

Note

This repository include fork of parson library because parson only handle 11 bits precision for fixed numbers. I think original policy is right on the implementing JSON. But not useful to handle 64bit numbers on mruby. If you want to contribute to the source parson.c or parson.h, please send PR to my fork.

Author

Yasuhiro Matsumoto (a.k.a mattn)

mruby-json's People

Contributors

genya0407 avatar hone avatar jemc avatar katzer avatar kazuho avatar matsumotory avatar mattn avatar ompugao avatar picohz avatar suzukaze avatar tagomoris avatar xxuejie avatar yamori813 avatar yasuyuki avatar yyamano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mruby-json's Issues

JSON generate adds addional characters to hash values

Hi, I am able to consistently reproduce this issue with the below example:

mirb - Embeddable Interactive Ruby Shell

a = "CCE-DG-=e0dcab8a-ae7f-4278-acb9-414460de5b50,ee49dcc3-8091-4609-a21e-f952374364b5|"
=> "CCE-DG-=e0dcab8a-ae7f-4278-acb9-414460de5b50,ee49dcc3-8091-4609-a21e-f952374364b5|"
b = /([A-Z0-9a-z]{8}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{12})/
=> /([A-Z0-9a-z]{8}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{12})/
c = b.match a
=> #<MatchData "e0dcab8a-ae7f-4278-acb9-414460de5b50" 1:"e0dcab8a-ae7f-4278-acb9-414460de5b50">
hash = {}
=> {}
hash[:test] = c[1]
=> "e0dcab8a-ae7f-4278-acb9-414460de5b50"
puts hash
{:test=>"e0dcab8a-ae7f-4278-acb9-414460de5b50"}
=> nil
d = JSON.generate hash
=> "{"test":"e0dcab8a-ae7f-4278-acb9-414460de5b50,ee49dcc3-8091-4609-a21e-f952374364b5|"}"
puts d
{"test":"e0dcab8a-ae7f-4278-acb9-414460de5b50,ee49dcc3-8091-4609-a21e-f952374364b5|"}
=> nil

Please note how d has "e0dcab8a-ae7f-4278-acb9-414460de5b50,ee49dcc3-8091-4609-a21e-f952374364b5|" as value for "test" whereas hash had "e0dcab8a-ae7f-4278-acb9-414460de5b50".

[mruby-1.3.0] mruby-json/test/json.rb:151: syntax error, unexpected '{'

The following errors occur with latest mruby-json and mruby-1.3.0:

/home/mruby/code/mruby/build/mrbgems/mruby-json/test/json.rb:151:49: syntax error, unexpected '{', expecting '}'
/home/mruby/code/mruby/build/mrbgems/mruby-json/test/json.rb:151:61: syntax error, unexpected '}', expecting keyword_end

Note: The errors only occur with mruby-1.3.0, not with mruby-1.4.0 or newer.

Fail: stringify object with to_json (mrbgems: mruby-json)

The following test from ruby-json fails:

Fail: stringify object with to_json (mrbgems: mruby-json)
 - Assertion[1] Failed: Expected to be equal
    Expected: "{\"foo\":\"foo\"}"
      Actual: "\"#<Foo:0x998980>\""

BTW there's no visible test summary on travis. Are you sure that they get executed?

Unicode problem after regenerating

A json string eg.

{"test": "\u4f60\u597d"}

parse it jsonObj = JSON.parse(s), then generate it newStr = JSON.generate(jsonObj)

the content of "newStr" is now

{"test": "你好"}

which is supposed to be identical with the original string( {"test": "\u4f60\u597d"} ).

rake all test was failed

Hi, rake all test was failed with mruby-json.

  • my environment
$ uname -a
Linux localhost.localdomain 3.13.5-103.fc19.x86_64 #1 SMP Mon Mar 3 18:46:36 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
  • rake all test
>>> Test host <<<
mrbtest - Embeddable Ruby Test

...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F.FF..FF
Fail: stringify object with float value
Fail: stringify object with boolean key and float value
Fail: stringify object with object key and float value
Fail: stringify object with several keys
Fail: stringify multi-byte
Total: 771
   OK: 766
   KO: 5
Crash: 0
 Time: 0.0307160 seconds
rake aborted!
Command failed with status (1): ["build/host/test/mrbtest"...]
/root/DEV/mruby/tasks/mruby_build.rake:191:in `run_test'
/root/DEV/mruby/Rakefile:106:in `block (2 levels) in <top (required)>'
/root/DEV/mruby/tasks/mruby_build.rake:12:in `instance_eval'
/root/DEV/mruby/tasks/mruby_build.rake:12:in `block in each_target'
/root/DEV/mruby/tasks/mruby_build.rake:11:in `each'
/root/DEV/mruby/tasks/mruby_build.rake:11:in `each_target'
/root/DEV/mruby/Rakefile:105:in `block in <top (required)>'
Tasks: TOP => test
(See full trace by running task with --trace)

hash to json strangeness

I've been struggling with a hash to json conversion that fails but only some of the time.

the output from mirb is correct

mirb> JSON.stringify({:id=>"c58", :method=>"vm.add", :params=>{:name=>"eval1", :url=>"https://gist.github.com/donpdonp/aab0987a4e062ca66d6a"}})
 => "{\"id\":\"c58\",\"method\":\"vm.add\",\"params\":{\"name\":\"eval1\",\"url\":\"https://gist.github.com/donpdonp/aab0987a4e062ca66d6a\"}}"

when I stringify the same object in mruby inside the C app, the output is wrong.
the ruby creating the output is at
https://gist.github.com/donpdonp/07bcb50f4f61680962d3#file-vm-rb-L104
notice the "name" : "eval1 url...."

vm to_s {:id=>"c58", :method=>"vm.add", :params=>{:name=>"eval1", :url=>"https://gist.github.com/donpdonp/aab0987a4e062ca66d6a"}}
vm stringify {"id":"c58","method":"vm.add","params":{"name":"eval1 https://gist.github.com/donpdonp/aab0
987a4e062ca66d6a","url":"https://gist.github.com/donpdonp/aab0987a4e062ca66d6a"}}

If I add a debug print statement like this

diff --git a/src/mrb_json.c b/src/mrb_json.c
index a04871a..1262748 100644
--- a/src/mrb_json.c  
+++ b/src/mrb_json.c
@@ -95,6 +95,7 @@ mrb_value_to_string(mrb_state* mrb, mrb_value value) {
         mrb_str_concat(mrb, str, enckey);  
         mrb_str_cat_cstr(mrb, str, ":");
         obj = mrb_hash_get(mrb, value, key);
+        printf("js k:%s v:%s\n", mrb_string_value_cstr(mrb, &key), mrb_string_value_cstr(mrb, &obj));
         mrb_str_concat(mrb, str, mrb_value_to_string(mrb, obj));
         if (n != l - 1) {
           mrb_str_cat_cstr(mrb, str, ",");

The output becomes correct where "name": "eval1" without the url

vm to_s {:id=>"eys", :method=>"vm.add", :params=>{:name=>"eval1", :url=>"https://gist.github.com/donpdon
p/aab0987a4e062ca66d6a"}}
js k:id v:eys
js k:method v:vm.add
js k:params v:{:name=>"eval1", :url=>"https://gist.github.com/donpdonp/aab0987a4e062ca66d6a"}
js k:name v:eval1
js k:url v:https://gist.github.com/donpdonp/aab0987a4e062ca66d6a
vm stringify {"id":"eys","method":"vm.add","params":{"name":"eval1","url":"https://gist.github.com/donpd
onp/aab0987a4e062ca66d6a"}}

I apologize for the complicated setup and for filing a bug when the mirb output is correct, but I cant think of anywhere else to look for this problem. Do you have any ideas here? thanks.

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.