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
3
votes
1 answer

JSON.stringify seeming to not work as expected

I have the following code; var rawData = []; rawData['uid'] = 105; rawData['auth_customer'] = true; console.log(rawData); var postData = JSON.stringify(rawData); console.log(postData); The first console.log is outputting; [uid: 105,…
Skittles
  • 2,866
  • 9
  • 31
  • 37
3
votes
2 answers

Getting "System.Collections.Generic.List`1[System.String]" in CSV File export when data is okay on screen

I am new to PowerShell and trying to get a list of VM names and their associated IP Addresses from within Hyper-V. I am getting the information fine on the screen but when I try to export to csv all I get for the IP Addresses is…
G Beach
  • 115
  • 1
  • 3
  • 10
3
votes
1 answer

Is there a simple way to customize how arrays are formatted by JSON.stringify?

I often want to "pretty print" (include extra white-space to make it easier for humans to interpret) JavaScript objects, and JSON.stringify(myObject, null, " ") usually suffices for this. However, in many cases, there are arrays of numbers that I…
jacobq
  • 11,209
  • 4
  • 40
  • 71
3
votes
2 answers

JSON object from Stringified value

Here is my very simple C# class object that I am trying to turn into a JSON string and stringifying: public class rTestObject { public rTestObject() { Name = "Hello"; State = 7; } public string Name { get; set; } …
MrLister
  • 634
  • 7
  • 32
3
votes
1 answer

How to "reset" object's property order? JSON.stringify() preserves them

Two identical objects, property order is the only difference: const obj1 = {aaa: 1, bbb: 2, ccc: 3}; const obj2 = {ccc: 3, aaa: 1, bbb: 2}; Now if I use JSON.stringify() it will preserve order and…
cimak
  • 1,765
  • 3
  • 15
  • 18
3
votes
3 answers

Parentheses in an object literal

Are parentheses in an object literal simply the grouping operator? node-stringify will convert: [ { a: 1 } ] to the string: [({'a':1}),({'a':2})] Can I take it that the parentheses here have no impact to the data, ie it is totally the same even…
Old Geezer
  • 14,854
  • 31
  • 111
  • 198
3
votes
1 answer

JSON.stringify(value[, replacer[, space]])

As per MDN Docs, the JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. When…
samxyzbac
  • 31
  • 3
3
votes
1 answer

javascript: smallest JSON.stringify for Float32Array?

FireFox 46.0.1: I am using 3rd-party (easyrtc) software to send 15KB chunks of Float32Arrays between peers. Easyrtc insists that the data be JSON-able. Unfortunately, JSON.stringify yields a string more than twice as long as the original data: …
Pete T
  • 76
  • 1
  • 7
3
votes
1 answer

Why my replacer function in JSON.stringify(value, replacer) doesn't receive keys in Angular application?

Trying to implement JSON.stringify as explained here: Hide certain values in output from JSON.stringify() and exclude some fields from serialization but it doesn't work. For example in my controller I've the following…
Anatoly
  • 5,056
  • 9
  • 62
  • 136
3
votes
5 answers

Stringification of int in C/C++

The below code should output 100 to my knowledge of stringification. vstr(s) should be expanded with value of 100 then str(s) gets 100 and it should return the string "100". But, it outputs "a" instead. What is the reason? But, if I call with macro…
amin__
  • 1,018
  • 3
  • 15
  • 22
3
votes
2 answers

Is there a way to JSON.stringify an HTML dom object? [JavaScript]

I am trying to load in a external html file and stringify the contents within the body but can't seem to do so without it producing undesired results. Is there even a way to do this? var xhr = new XMLHttpRequest(); function loadFile(){ …
user3612986
  • 315
  • 2
  • 7
  • 18
3
votes
2 answers

Dump JavaScript object including function bodies as "good enough" formattable code

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…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
3
votes
2 answers

JSON.stringify does not convert arrays

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…
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
3
votes
1 answer

Synchronously convert Blob to base64 string in Javascript

The only way I found to base64 encode a data Blob to put it in a JSON string, is to use the asyncronous readAsDataUrl() function. var reader = new window.FileReader(); reader.readAsDataURL(blob); reader.onloadend = function() { base64data =…
Sebastian Barth
  • 4,079
  • 7
  • 40
  • 59
3
votes
0 answers

Stringify an object with function expressions - javascript

Is it possible? I need to stringify js object with function expressions with all value types on other fields to be not changed. Example: I have such javascript object - var obj = { propText: "some text", propBool: true, propNum:…
Kosmetika
  • 20,774
  • 37
  • 108
  • 172