Use Ruby's Native JSON conversion rather than outputting a JSON string
See original GitHub issuei.e instead of:
body = " { \"a\": 123 }"
Do:
require 'json'
body = { a: 123 }.to_json
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to convert a ruby hash object to JSON? - Stack Overflow
I can understand ActiveRecord is a Rails object, but Hash is not native to Rails, it's a pure Ruby object. So in Rails...
Read more >Module: JSON (Ruby 2.6.3)
JSON.generate only allows objects or arrays to be converted to JSON syntax. to_json , however, accepts many Ruby classes even though it acts...
Read more >Handling JSON Data - Real World OCaml
Our first task is to parse the JSON into a more structured OCaml type so that we can use static typing more effectively....
Read more >flori/json: JSON implementation for Ruby - GitHub
It's recommended to use the extension variant of JSON, because it's faster than the pure ruby variant. If you cannot build it on...
Read more >JSON.stringify() - JavaScript - MDN Web Docs
The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
note: re 1. above, https://github.com/Kong/httpsnippet/pull/285 made the
OpenSSL::SSL::VERIFY_NONE
line configurable.@dimitropoulos Both works, but
JSON.generate
is better (more obvious, less risk of conflict with other ruby gems).Easier to understand that this is the
json
gem being used (it’s used in both cases, but withto_json
that’s not very obvious), and there is no risk of some other code having patched/shadowed theto_json
method (unlikely, but can happen).However, after looking at the source for Python (fairly similar to Ruby), I realize that it’s some work.
I’ve tried to put something together here, that would go onto these lines:
https://github.com/Kong/httpsnippet/blob/911ab772bc2b1cd271024ea1efeab14614d28de0/src/targets/ruby/native/client.ts#L77-L79
Would need to add this as a helper (similar to the Python snippet):
See these two files for background, and the necessary require calls etc. to load the helper.
https://github.com/Kong/httpsnippet/blob/911ab772bc2b1cd271024ea1efeab14614d28de0/src/targets/python/requests/client.ts
https://github.com/Kong/httpsnippet/blob/911ab772bc2b1cd271024ea1efeab14614d28de0/src/targets/python/helpers.ts