Coder Social home page Coder Social logo

oj_mimic_json's People

Contributors

jasonporritt avatar ohler55 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

oj_mimic_json's Issues

ascii_only=>true option is ignored

JSON mudule supports ascii_only option in similar way Oj does, but not directly in JSON.dump.
oj_mimic_json doesn't pass this option to Oj.

2.0.0-p598 :003 > require 'json'
2.0.0-p598 :004 > JSON.dump("a😬sdf") # => "\"a😬sdf\"" 
2.0.0-p598 :005 > JSON.generate(["a😬sdf"], ascii_only: true) # => "[\"a\\ud83d\\ude2csdf\"]" 
2.0.0-p598 :006 > JSON.dump_default_options[:ascii_only]=true
2.0.0-p598 :007 > JSON.dump(["a😬sdf"]) # => "[\"a\\ud83d\\ude2csdf\"]" 
2.0.0-p598 :008 > require 'oj_mimic_json'
2.0.0-p598 :009 > JSON.generate(["a😬sdf"], ascii_only: true) # => "[\"a😬sdf\"]" 
2.0.0-p598 :010 > JSON.dump(["a😬sdf"]) # => "[\"a😬sdf\"]" 

JSON.parse with option object_class: OpenStruct

I guess, this issue relates to my situation.
If I include
gem 'oj_mimic_json'
into my rails application, I could not use JSON.parse with object_class: OpenStruct option. It breakes parsing of json into OpenStruct and result is still a hash instead of struct object

Is there a workaround?

Decoding floats with trailing zeros results in wrong values

When requiring oj_mimic_json, decoding a float with more than 18 decimal places, including more than 4 trailing zeros, results in wrong values:

[19] pry(main)> Oj.load('{"foo":0.1000000000000000000}')
=> {"foo"=>-0.11838881245526249}
[20] pry(main)> Oj.load('{"foo":0.100000000000000000}')
=> {"foo"=>0.1}
[21] pry(main)> Oj.load('{"foo":0.110000000000000000}')
=> {"foo"=>0.11}
[22] pry(main)> Oj.load('{"foo":0.1100000000000000000}')
=> {"foo"=>-0.13022769370078874}
[23] pry(main)> Oj.load('{"foo":0.1000000000000000000}')
=> {"foo"=>-0.11838881245526249}
[24] pry(main)> Oj.load('{"foo":0.1100000000000000000}')
=> {"foo"=>-0.13022769370078874}
[25] pry(main)> Oj.load('{"foo":0.1110000000000000000}')
=> {"foo"=>-0.13141158182534138}
[26] pry(main)> Oj.load('{"foo":0.1111000000000000000}')
=> {"foo"=>-0.13152997063779662}
[27] pry(main)> Oj.load('{"foo":0.1111100000000000000}')
=> {"foo"=>-0.13154180951904215}
[28] pry(main)> Oj.load('{"foo":0.1111110000000000000}')
=> {"foo"=>-0.13154299340716671}
[29] pry(main)> Oj.load('{"foo":0.1111111000000000000}')
=> {"foo"=>-0.13154311179597916}
[30] pry(main)> Oj.load('{"foo":0.1111111100000000000}')
=> {"foo"=>-0.1315431236348604}
[31] pry(main)> Oj.load('{"foo":0.1111111110000000000}')
=> {"foo"=>-0.13154312481874852}
[32] pry(main)> Oj.load('{"foo":0.1111111111000000000}')
=> {"foo"=>-0.13154312493713735}
[33] pry(main)> Oj.load('{"foo":0.1111111111100000000}')
=> {"foo"=>-0.13154312494897621}
[34] pry(main)> Oj.load('{"foo":0.1111111111110000000}')
=> {"foo"=>-0.1315431249501601}
[35] pry(main)> Oj.load('{"foo":0.1111111111111000000}')
=> {"foo"=>-0.1315431249502785}
[36] pry(main)> Oj.load('{"foo":0.1111111111111100000}')
=> {"foo"=>-0.13154312495029036}
[37] pry(main)> Oj.load('{"foo":0.1111111111111110000}')
=> {"foo"=>#<BigDecimal:1f157b0,'0.1111111111 11111E0',18(36)>}
[38] pry(main)> Oj.load('{"foo":0.1111111111111110000}')['foo'].to_f
=> 0.111111111111111

This does not happen if only oj is being required.

JSON::ParserError: unexpected characters after the JSON document () at line 30, column 2 [sparse.c:642]

using oj_mimic_json together with rails 6 action_text fails with JSON::ParserError: unexpected characters after the JSON document () at line 30, column 2 [sparse.c:642].

how to reproduce:

rails _6.0.2.1_ new testojmimic

add the following gems:

gem 'oj'
gem 'oj_mimic_json'

yields in:

testojmimic ry$ bundle exec rails action_text:install
rails aborted!
JSON::ParserError: unexpected characters after the JSON document () at line 30, column 2 [sparse.c:642]
/Users/ry/Sites/test/testojmimic/bin/rails:9:in `<top (required)>'
/Users/ry/Sites/test/testojmimic/bin/spring:15:in `require'
/Users/ry/Sites/test/testojmimic/bin/spring:15:in `<top (required)>'
./bin/rails:3:in `load'
./bin/rails:3:in `<main>'
Tasks: TOP => app:template
(See full trace by running task with --trace)
Copied migration 20200112140326_create_active_storage_tables.active_storage.rb from active_storage
Copied migration 20200112140327_create_action_text_tables.action_text.rb from action_text

remove gem 'oj_mimic_json' (keep gem oj, again bundle install) then run bundle exec rails action_text:install again, runs without error:

Copying actiontext.scss to app/assets/stylesheets
      create  app/assets/stylesheets/actiontext.scss
Copying fixtures to test/fixtures/action_text/rich_texts.yml
      create  test/fixtures/action_text/rich_texts.yml
Copying blob rendering partial to app/views/active_storage/blobs/_blob.html.erb
      create  app/views/active_storage/blobs/_blob.html.erb
Installing JavaScript dependencies
         run  yarn add trix@^1.0.0 @rails/actiontext@^6.0.2-1 from "."
yarn add v1.9.0-20180627.0947
[1/4] 🔍  Resolving packages...
⠁ (node:3868) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^4.0.0".
[4/4] 📃  Building fresh packages...

success Saved lockfile.
success Saved 2 new dependencies.
info Direct dependencies
├─ @rails/[email protected]
└─ [email protected]
info All dependencies
├─ @rails/[email protected]
└─ [email protected]
✨  Done in 15.46s.
Adding trix to app/javascript/packs/application.js
      append  app/javascript/packs/application.js
Adding @rails/actiontext to app/javascript/packs/application.js
      append  app/javascript/packs/application.js

Tried again with a fresh rails app, found here: https://github.com/swiknaba/testojmimic
ruby 2.6.5
rails 6.0.2.1

update (July 15, 2021)
updated the repo to:
ruby 2.7.3
rails 6.1.4
-> the error is still present

update (Sept 30, 2022)
minor updates:
ruby 2.7.5
rails 6.1.7
-> and also added a docker image to test the dummy app without messing with the install on your local machine; see this comment further below: #7 (comment)

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.