Found 206 Articles for JSON

Read by key and parse as JSON in JavaScript

AmitDiwan
Updated on 20-Nov-2020 09:52:57

145 Views

Suppose, we have a JSON array like this −const arr = [{    "data": [       { "W": 1, "A1": "123" },       { "W": 1, "A1": "456" },       { "W": 2, "A1": "4578" },       { "W": 2, "A1": "2423" },       { "W": 2, "A1": "2432" },       { "W": 2, "A1": "24324" }    ] }];We are required to write a JavaScript function that takes in one such array and converts it to the following JSON array −[    {       "1": ... Read More

How to convert JSON text to JavaScript JSON object?

AmitDiwan
Updated on 16-Jul-2020 06:57:01

642 Views

The JSON parse() method is used for converting a JSON text to a JavaScript object.Following is the code for converting JSON text to JavaScript JSON object −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } JSON parse() Method {"name":"Rohan", "sports":["Cricket", "Football"], "country":"India"} CLICK HERE Click on the above button to parse the above JSON string    let ... Read More

Parsing JSON array with PHP foreach

AmitDiwan
Updated on 07-Apr-2020 11:11:49

5K+ Views

The below code can be used to parse JSON array −Example Live Demo

How to Install Bower on Ubuntu

Sharon Christine
Updated on 20-Jan-2020 12:40:22

902 Views

Bower is a bundled supervisor for the web and offers a conventional technique for the drawbacks in entrance-finish package management. It basically maintains and monitors all packages and examines new updates. Bower also makes use of a take place file called bower.Json to keep track of applications. This article explains about -“How to install bower on Ubuntu”.To install bower, we require pre-installed Node.js and NPM. To verify the node.js version, use the following command-$ node -vThe sample output should be like this-v6.9.2To verify the NPM version, use the following command$ npm -vThe sample output should be like this-3.10.9If you wants ... Read More

How To Install and Configure MongoDB on CentOS 7

Sharon Christine
Updated on 20-Jan-2020 09:57:59

324 Views

In this article, we will learn how to install and configure the MongoDB on CentOS 7, MongoDB which is an open-source and free database (is a NoSQL database), means it is a document-oriented database, it stores the document which is similar structurally to JSON (in MongoDB it is called as BSON) with high availability, performance and auto scaling. Unlike the RDBMS, it doesn’t need any predefined database schema for adding the data to the database tables. We can alter the schema any point of time without disturbing the existing schema.PrerequisitesCentos 7 installed on the Linux Machine.A user with root user ... Read More

Difference between JSON and XML

Mahesh Parahar
Updated on 24-Feb-2020 08:08:04

254 Views

Both JSON and XML are the most popular data transversal resources in programming world.Due to their various important characteristics and features both of these resources are widely used globally.On the basis of their features following are the important differences JSON and XMLSr. No.KeyJSONXML1AbbreviationJSON stands for JavaScript Object Notation.On other hand XML stands for Extensible Mark-up Language.2TypeJSON format is data interchangeable.On other hand XML format is Mark-up language.3Based onJSON is derived from JavaScript language from where it puts the feature to represents the data in a way of representing objects.On other hand XML is derived from SGML and uses tag structure ... Read More

Proper way to catch exception from JSON.parse

Ayush Gupta
Updated on 02-Dec-2019 06:17:05

3K+ Views

The best way to catch invalid JSON parsing errors is to put the calls to JSON.parse() to a try/catch block.Examplefunction parseJSONSafely(str) {    try {       return JSON.parse(str);    }    catch (e) {       console.err(e);       // Return a default object, or null based on use case.       return {}    } }

How to Send and Receive JSON Data to and from the Server

Ayush Gupta
Updated on 27-Nov-2019 10:20:22

3K+ Views

JavaScript can send network requests to the server and load JSON. JS does this using something called AJAX. AJAX stands for Asynchronous JavaScript and XML. JS has an API, fetch, to GET(receive) and POST(send) information to the server.You can use fetch to GET JSON data in the following way −Exampleconst URL = 'https://jsonplaceholder.typicode.com/todos/1' // Send a GET request without any data to the server fetch(URL, {method: "GET"}) // Get the JSON data from the raw response    .then(res => res.json()) // Print the result    .then(console.log)OutputThis will give the output −{    "userId": 1,    "id": 1,    "title": "delectus ... Read More

What to use @SerializedName annotation using Gson in Java?

raja
Updated on 09-Jul-2020 08:17:53

6K+ Views

The @SerializedName annotation can be used to serialize a field with a different name instead of an actual field name. We can provide the expected serialized name as an annotation attribute, Gson can make sure to read or write a field with the provided name.Syntax@Retention(value=RUNTIME) @Target(value={FIELD, METHOD}) public @interface SerializedNameExampleimport com.google.gson.*; import com.google.gson.annotations.*; public class SerializedNameTest {    public static void main(String args[]) {       Gson gson = new GsonBuilder().setPrettyPrinting().create();       Person person = new Person(115, "Raja Ramesh", "Hyderabad");       String jsonStr = gson.toJson(person);       System.out.println(jsonStr);    } } // Person class class ... Read More

How to implement custom JsonAdapter using Gson in Java?

raja
Updated on 09-Jul-2020 08:15:08

2K+ Views

The @JsonAdapter annotation can be used at field or class level to specify the Gson. The TypeAdapter class can be used to convert Java objects to and from JSON. By default, Gson library converts application classes to JSON by using built-in type adapters but we can override it by providing custom type adapters.Syntax@Retention(value=RUNTIME) @Target(value={TYPE, FIELD}) public @interface JsonAdapterExampleimport java.io.IOException; import com.google.gson.Gson; import com.google.gson.TypeAdapter; import com.google.gson.annotations.JsonAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; public class JsonAdapterTest {    public static void main(String[] args) {       Gson gson = new Gson();       System.out.println(gson.toJson(new Customer()));    } } // Customer class class Customer { ... Read More

Previous 1 ... 3 4 5 6 7 ... 21 Next
Advertisements