FAQ Database Discussion Community


How do I convert a Ruby hash so that all of its keys are strings

ruby,hash,stringify
I have a ruby hash which looks like: { id: 123, name: "test" } I would like to convert it to: { "id" => 123, "name" => "test" } ...

extension crash on exporting stringified/encodeURIComponent data to file

javascript,google-chrome-extension,stringify,encodeuricomponent
It is about exporting extension data from options page. I have array of objects, with stored page screenshots encoded in base64, and some other minor obj properties. I'm trying to export them with this code: exp.onclick = expData; function expData() { chrome.storage.local.get('extData', function (result) { var dataToSave = result.extData; var...

Replacing values in JSON object

javascript,arrays,json,stringify
I have the following JSON object data returned from my apicontroller : > [ {"id":2,"text":"PROGRAMME","parent":null}, > {"id":3,"text":"STAGE","parent":2}, > {"id":4,"text":"INFRA","parent":2}, > {"id":5,"text":"SYSTEM","parent":3}, > {"id":6,"text":"STOCK","parent":3}, {"id":7,"text":"DPT","parent":3}, > {"id":9,"text":"EXTERNAL","parent":null} ] I want to replace "parent":null with "parent":'"#"' I have tried the code below, but it is only replacing the first occurrence of "parent":null....

JSON.stringify does not convert arrays

javascript,arrays,json,stringify
I know that I have gone about this the wrong way and very honestly it could be because I am handling the recursion incorrectly, but if so I am unsure where I have gone wrong. Here is the link to the example. Here is the JavaScript - function propertyTest(currentObject, key)...

Dump JavaScript object including function bodies as “good enough” formattable code

javascript,serialization,javascript-objects,stringify
There are lots of old questions about dumping JavaScript objects. But of the ones which specify dumping the contents of functions, I can only find ones that emit those functions as strings in quotes (with internal quotes escaped). What I want is something that dumps objects, including functions, in full,...

Call the replacer *before* the object's toJSON?

javascript,json,stringify
Is there a way to get my replacer called before an object's own toJSON transforms it, so that I can work with the original object rather than its JSON-friendly form, without overriding the toJSON on the object or its prototype, pre-processing the object, or writing my own version of JSON.stringify?...

Pull specific data from JSON response

javascript,arrays,json,stringify
I have a JSON response which I convert to string in javascript by doing var myObject = JSON.stringify(data); This prints out the results fine but I need to be able to pull specific data like myObject.route.locationSequence[1] or myObject.route.distance. However neither of those seem to work. Below is my JSON response....

Extract outerHTML variable from $table

javascript,jquery,stringify,outerhtml
I have not been able to find any information about this, so forgive the lack of knowledge. I created a table using the code below, but now I want to use the table with a jQuery plugin but in order to do it I need to print out the table,...

How to properly store an array of objects in a cookie using json.stringify?

javascript,jquery,json,parsing,stringify
I'm trying to store an array of objects in a cookie using JSON.Stringify but I'm having a problem when I parse the cookie and try to push a new object to the array to then stringify it again. It tells me that comments.push is not a function. var comments =...

How to De-Stringify Stringified JavaScript?

javascript,parsing,eval,stringify
How to 'de-stringify' JavaScript code that has been stringified? JSON.parse does not seem to work. We want to store JavaScript code in the database and then retrieve it and then eval it. Here's the code in the database: //# sourceURL=journal.js function onBlur(e) { var drAmount = script.getGridRowFieldValue('debitamount', e.rowuid) var crAmount...

PHP array stringify

php,arrays,stringify
In a lyrics application I'm coding, I'm using an array to print an artists table. The artists array looks like this: $artists = [ [ "Avril Lavigne" ], [ "3 Doors Down" ], [ "Celine Dion" ], [ "Evanescence" ], [ "Shania Twain" ], [ "Green Day" ], //... ];...

Parsing a JSON query string into a JSON object

json,node.js,mongoose,stringify
The query on the API is structured like this: ../myapi/products?_q=genre,retail_price&_a=g,p&p.gt=10&p.lt=20&g.eq=POP There are two arrays: _q which lists the query parameters and _a listing the corresponding aliases. So p -> retail_price and g -> genres I can parse this into: {$and : [ genre: { '$eq': 'POP' }, retail_price: { '$gt':...

TaffyDB - combine methods

javascript,distinct,stringify,taffydb
I'm really new to TaffyDB and JavaScript. How can I combine methods in TaffyDB? I'm trying to use distinct () and stringify(), which is not working var xyz = db().distinct("mnths").stringify (); console.log(xyz ); I get an error stating that stringify() is not supported. Thank you....