0

I cannot find any built-in functions/modules in Node.JS to convert a Ruby hash into a JSON object. I am very familiar with the method of using Ruby to do this, e.g. see How to convert a ruby hash object to JSON?. I am hoping for something similar in Node.JS. Of course, any workaround would also be fine. E.g., is there a way to run embedded ruby in Node.JS? From the searching I've done, it does not seem like there is anything "out-of-the-box" to do this.

Any help/pointers would be greatly appreciated! Thanks!

sconicelli
  • 101
  • 8
  • 2
    A hash is an internal data structure in Ruby. Node.js runs Javascript, which is a different language and has its own internal data structures. So you wouldn't really have a "Ruby hash" inside Node.js. Do you mean a string representation of a Ruby hash? If you print a Ruby hash it outputs it in a particular format (using Ruby notation such as "=>"). Are you loading this string into Node.js? If so you can write a parser that loads that string representation of a Ruby hash into a Javascript object, and then convert that object to JSON – Cormac Mulhall Nov 11 '21 at 15:41
  • "is there a way to run embedded ruby in Node.JS" If you have Ruby installed on the system, you can run Ruby via system calls. E.g. you could make a mini script which takes a Ruby hash as input and outputs a JSON hash. – max pleaner Nov 11 '21 at 18:36

0 Answers0