Comments (4)
The round trip isn't symmetric. How can I get symmetric dump/parse?
# current
> JSON.parse JSON.generate(:foo)
=> {"json_class"=>"Symbol", "s"=>"foo"}
# ideal
> JSON.parse JSON.generate(:foo)
=> :foo
from json.
Ah, ok:
> JSON.parse JSON.generate(:foo), create_additions: true
=> :foo
Still need support for Hash and recursive structures.
from json.
Looks like it's only an issue with Hash keys. Works with Arrays and Hash values.
> JSON.parse(JSON.generate([1, [:foo, "mike"]]), create_additions: true)
=> [1, [:foo, "mike"]]
> JSON.parse(JSON.generate({:foo => "mike", 123 => :bar}), create_additions: true)
=> {"foo"=>"mike", "123"=>:bar}
But unfortunately Hash keys are the main usecase for Symbols in method arguments.
from json.
I think I understand now. "JSON keys are strings, always on the left of the colon, and must be wrapped in double quotes". Converting a Symbol to a Hash is ok but it can't be used as a key in a larger Hash. The code would need to be modified to perform something similar to ActiveJob here:
from json.
Related Issues (20)
- JSON gem is slow parsing integers/floats when there's multiple threads executing at once (in Ractors) HOT 1
- Hilarious surrogate(?) bug
- JSON.pretty_generate generates wrong format json output to MRI for at least an empty hash version 9.4.0.0 HOT 4
- JRuby extension fails to build on Windows HOT 1
- How to use both, pure and ext variant
- Streaming enhancements for dumping
- Behaviour change between 2.5.1 and 2.6.0
- Test
- JSON.parse Alters Encoding of Passed String Unexpectedly
- Shorten reference to input data in error message
- json-1.8.6/lib/json/common.rb:155:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError) HOT 1
- CHANGES.md is not update for version 2.6.3
- https://www.example.com/proxy.pac
- JSON.dump does not work in version 2.7.0 when the argument is an implicit Hash HOT 5
- Wrong number of arguments for dump in 2.7.0 HOT 4
- JSON.dump inconsistent output for hash
- Compatibility with new ruby 3.3.0
- README references file which does not exist HOT 1
- Support Symbols for Hash keys HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json.