Skip to content

Tag: json

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: But this gives me a single line file that is hard to read. Is there an easy way to format it as a readable JSON file, with newlines and indentation? Answer The JSON.stringify has three parameters, you can use th…

How can I get the index from a JSON object with value?

This is my JSON string. Now, I have the value allInterests and I want to find out the index (this case; it is ‘7’) of this object in the above string. I tried the following code, but it always returns -1. Answer You will have to use Array.find or Array.filter or Array.forEach. Since your value is …

Combine json arrays by key, javascript

I need to combine two json arrays, delivered by two rest services. The entries with the same “id” belong together. I need a combined/copied/cloned json array in javascript in the following way (my model in angular2): Is there a way to combine them? The parameter names are not defined exactly and i…

Export a Json object to a text File

I’m trying to write a Json object (JsonExport) and I’d like to write its content into a text file. I’m using max4live to export data from Audio DAW to Json in order to export to a server, but after that I would like to see the whole Json Object in a text file: The compiler runs with no error…

Saving JSON in Electron

I am building an app using Electron. In this app, I am building a data structure using JSON. My data structure looks like this: I want to save this JSON to a file called “data.json”. I want to save it to a file because I want to load the next time the application starts. My challenge is, I do not

How to assign JSON string to Javascript variable?

What is the correct way to assign a JSON string to a variable? I keep getting EOF errors. http://jsfiddle.net/x7rwq5zm/1/ Answer You have not escaped properly. You make sure you do: The easier way would be to just convert an existing object to a string using JSON.stringify(). Would recommend this as much as p…

JSON stringify a Set

How would one JSON.stringify() a Set? Things that did not work in Chromium 43: I would expect to get something similar to that of a serialized array. Answer JSON.stringify doesn’t directly work with sets because the data stored in the set is not stored as properties. But you can convert the set to an ar…