Questions tagged [stringify]

A function that converts a JavaScript value to a JavaScript Object Notation (JSON) string.

A common use of JSON is to exchange data to/from a web server. When sending data to a web server, the data has to be a "string". Convert a JavaScript object into a string with JSON.stringify().

JSON.stringify() documentation.

718 questions
15
votes
2 answers

Is there a way to use something equivalent to json.dumps in javascript

I am supplying a list of objects to my django template. I have a conditions where i am accessing one of the field of object in template which is a json field containing u' characters like {u'option': False, u'name': u'test string'} We usually use…
Rajat Vij
  • 317
  • 2
  • 6
  • 16
14
votes
3 answers

JSON.stringify(array) surrounded with square brackets

I'm trying to get an array of data to insert into multiple columns in an sqlite database, I'v got it almost working with this: function InsertData(dbData){ var valueArray = [], dataArray = []; var values = Object.keys(dbData); for(var key in…
Devcon
  • 767
  • 2
  • 8
  • 23
13
votes
3 answers

JSON stringify and PostgreSQL bigint compliance

I am trying to add BigInt support within my library, and ran into an issue with JSON.stringify. The nature of the library permits not to worry about type ambiguity and de-serialization, as everything that's serialized goes into the server, and never…
vitaly-t
  • 24,279
  • 15
  • 116
  • 138
12
votes
4 answers

JSON.stringify ignore some object members

Heres a simple example. function Person() { this.name = "Ted"; this.age = 5; } persons[0] = new Person(); persons[1] = new Person(); JSON.stringify(persons); If I have an array of Person objects, and I want to stringify them. How can I return…
Moz
  • 1,494
  • 6
  • 21
  • 32
12
votes
1 answer

Aurelia aurelia-fetch-client and with JSON POST

I have the following code which works is working well: import {inject} from 'aurelia-framework'; import {HttpClient, json} from 'aurelia-fetch-client'; @inject(HttpClient) export class Items { heading = 'Items'; apiKey = ""; …
user1513388
  • 7,165
  • 14
  • 69
  • 111
11
votes
1 answer

What is the use of stringify and then parse a JSON object

Is there any specific reason for stringifya JSON object and parseit again. Obviously it will return the Initial object itself. is there advantage of doing this? Code 1: stringify and then parse var textstring = '{ "employees" : [' + '{…
Venkat
  • 2,549
  • 2
  • 28
  • 61
11
votes
1 answer

How to JSON.stringify an array of objects

I am attempting to JSON.stringify() the following key/value pair, where the value is an array of objects. var string = JSON.stringify({onlineUsers : getUsersInRoom(users, room)}); This is incorrect and gives the following error: var string =…
crmepham
  • 4,676
  • 19
  • 80
  • 155
11
votes
2 answers

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

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…
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
11
votes
3 answers

use a variable in JSON.stringify

I use stringify in my node restful server to provide data: answer = JSON.stringify({activities: result}, null, '\t'); return answer where result is a js object; i receive the correct output for this: { "activities": [ { "id": 1, …
Cereal Killer
  • 3,387
  • 10
  • 48
  • 80
11
votes
3 answers

Why doesn't JSON.stringify display object properties that are functions?

Why doesn't JSON.stringify() display prop2? var newObj = { prop1: true, prop2: function(){ return "hello"; }, prop3: false }; alert( JSON.stringify( newObj ) ); // prop2 appears to be missing alert( newObj.prop2() ); // prop2 returns…
egret
  • 179
  • 2
  • 8
10
votes
4 answers

Setting and getting object to local storage using stringify?

Creating an object called car: function car(temp){ this.brand=temp[0]; this.color=temp[1]; this.year=temp[2]; } var temp = ['Skoda', 'Red', '2012']; car = new car(temp); Setting object and stringify after reading from…
Sami
  • 2,311
  • 13
  • 46
  • 80
9
votes
1 answer

Download Object As Formatted JSON File

I followed this guide to download a JSON object from the browser. This is what my code looks like: var json = this.getEditorJSON(); var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(json)); var a =…
JaskeyLam
  • 15,405
  • 21
  • 114
  • 149
9
votes
1 answer

Python - Convert stringified list back to list

I have a stringified list: a = ['one', 'two'] a = str(a) After which, a would be "['one', 'two']" Is there a way to go from this string format back to a list like the original format? Thanks
intl
  • 2,753
  • 9
  • 45
  • 71
9
votes
2 answers

JSON.stringify() values as numbers?

I am using JSON.stringify() on html s to send through a websocket like so: JSON.stringify({ numberValue: $('#numberValue').val() }) but it encodes $('#numberValue').val() as a String. How can it be encoded as a Number?
user1382306
9
votes
2 answers

Converting a stringified json structure to PHP array

I'm saving a cookie with json data. Example of echo…
Andres SK
  • 10,779
  • 25
  • 90
  • 152
1 2
3
47 48