Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
JSON Articles
Page 2 of 16
How to Convert XML to JSON String in JavaScript?
Some popular formats for data exchange are XML (eXtensible Markup Language) and JSON (JavaScript Object Notation). Tags are used to structure XML, while JSON is a more condensed key-value format. In JavaScript apps, converting XML data to JSON is often required to facilitate data manipulation or integration with APIs that expect JSON format. Several techniques for converting XML to JSON using JavaScript are examined in this article, from using DOM parsing to employing custom JavaScript solutions. Understanding XML and JSON XML Example Pankaj 20 ...
Read MoreHow to Convert CSV File to JSON in JavaScript?
CSV (Comma-Separated Values) and JSON (JavaScript Object Notation) are two popular data formats. CSV is ideal for tabular data storage, while JSON is widely used in web applications. Converting CSV to JSON in JavaScript is a common requirement when working with data manipulation and API integrations. Understanding CSV and JSON Formats CSV Format: Data is stored in rows with values separated by commas. Each row represents a record, and the first row typically contains column headers. name, age, city Pankaj, 20, Surat Neeraj, 18, Raipur JSON Format: Data is represented as an array of ...
Read MoreHow to Convert JavaScript Class to JSON in JavaScript?
JavaScript classes serve as blueprints for creating objects with properties and methods. When working with APIs or data storage, you often need to convert class instances to JSON format for serialization. This article demonstrates several approaches to convert JavaScript classes to JSON with practical examples. Approaches to Convert JavaScript Class to JSON Using JSON.stringify() Method Adding a Custom toJSON() Method Using Object.assign() Method Using Custom Serializer Using JSON.stringify() Method JSON.stringify() is the most straightforward method to convert a class ...
Read MoreRead by key and parse as JSON in JavaScript
In JavaScript, you often need to group JSON data by specific keys and transform the structure. This tutorial shows how to read data by key values and reorganize it into a grouped JSON format. Problem Statement Given a JSON array with nested data, we want to group items by a specific key (like "W") and create a new structure where each group becomes a separate object. Starting with this data structure: const arr = [{ "data": [ { "W": 1, "A1": "123" }, ...
Read MoreFinding the smallest value in a JSON object in JavaScript
Finding the smallest value in a JSON object is a common task in JavaScript. This involves traversing through an object's properties and comparing their numeric values to determine the minimum. When working with objects that contain numeric values, we need to iterate through all properties and find the one with the smallest value. JavaScript provides several approaches to accomplish this efficiently. Example Here's how to find the smallest value using the reduce() method: const obj = { "a": 4, "b": 2, "c": 5, ...
Read MoreHow to turn a JSON object into a JavaScript array in JavaScript ?
Converting a JSON object with numeric string keys into a JavaScript array is a common operation. This is particularly useful when dealing with API responses or data structures that use indexed properties. The Problem Consider this JSON object where index keys are mapped to string values: const obj = { "0": "Rakesh", "1": "Dinesh", "2": "Mohit", "3": "Rajan", "4": "Ashish" }; console.log(typeof obj); // "object" object Method 1: Using Object.keys() and forEach() This approach iterates through object keys and maps ...
Read MoreDeep Search JSON Object JavaScript
Deep searching a JSON object means recursively traversing through all nested objects and arrays to find elements that match specific criteria. This is useful when you need to locate objects buried deep within complex data structures. The Problem Suppose we have the following nested JSON object: const obj = { id: 1, title: 'hello world', child: { id: null, title: 'foobar', ...
Read MoreConvert JSON to another JSON format with recursion JavaScript
Suppose, we have the following JSON object − const obj = { "context": { "device": { "localeCountryCode": "AX", "datetime": "3047-09-29T07:09:52.498Z" }, "currentLocation": { "country": "KM", ...
Read MoreMerge JSON array date based JavaScript
When working with JSON arrays containing objects with date properties, you often need to merge objects that share the same date. This is common when combining data from different sources or consolidating time-series data. Suppose we have the following array of objects: const arr = [ { "date": "2010-01-01", "price": 30 }, { "date": "2010-02-01", ...
Read MoreTransform tree from DB format to JSON format in JavaScript
When working with database records, data is often stored in a flat structure with parent-child relationships defined by IDs. This tutorial shows how to transform such flat data into a hierarchical tree structure in JavaScript. The Problem Suppose we have an array of objects representing geographical regions from a database: const arr = [ {"id":7, "name":"Kuwait", "parentId":2}, {"id":4, "name":"Iraq", "parentId":2}, {"id":10, "name":"Qatar", "parentId":2}, {"id":2, "name":"Middle East", "parentId":1}, {"id":3, "name":"Bahrain", "parentId":2}, {"id":6, "name":"Jordan", ...
Read More