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 4 of 16
Get value for key from nested JSON object in JavaScript
In JavaScript, accessing values from nested JSON objects is a common task when working with APIs and complex data structures. We can retrieve nested values using dot notation, bracket notation, or custom functions. Before exploring different approaches, let's understand what JSON and nested JSON objects are: What is JSON and Nested JSON Objects? JSON (JavaScript Object Notation) is a lightweight, text-based format for representing structured data. It's widely used for data transmission between web applications and servers. Nested JSON objects contain objects within other objects, creating a hierarchical structure. Each nested property has a unique path ...
Read MoreJSON group object in JavaScript
In JavaScript, grouping JSON objects means organizing data by common properties or categories. This is useful for data analysis, filtering, and creating structured reports from collections of objects. What is JSON? JSON (JavaScript Object Notation) is a lightweight data format for transferring data between devices. JSON objects use key-value pairs where keys are strings and values can be strings, numbers, booleans, arrays, or nested objects. For example: {"name": "Alice", "age": 25}. const jsonData = [ { team: 'TeamA', score: 20 }, { ...
Read MoreCreate array from JSON object JavaScript
In this article, we will learn to create an array from JSON data in JavaScript. JSON is a widely used format for storing and exchanging data. A common use case involves extracting specific data from a JSON object or array and converting it into a separate array for further processing. What is JSON Data? JSON (JavaScript Object Notation) is a lightweight data format commonly used to store and exchange data between a server and a client. It represents data as key-value pairs and is easy for both humans and machines to read and write. In JavaScript, JSON objects ...
Read MoreEscaping/encoding single quotes in JSON encoded HTML5 data attributes
When embedding JSON data in HTML5 data attributes, single quotes can break HTML parsing. JavaScript provides several methods to properly escape or encode single quotes to ensure valid HTML output. The Problem with Single Quotes in Data Attributes Single quotes inside JSON values can break HTML attribute parsing when the attribute itself uses single quotes: // Problematic - single quote breaks HTML
Read MoreJSON. stringify( ) function in JavaScript
The JSON.stringify() method converts a JavaScript object or value to a JSON string. This is the reverse of JSON.parse() which converts JSON strings back to JavaScript objects. Syntax JSON.stringify(value, replacer, space) Parameters value: The JavaScript value to convert to JSON string (required) replacer: Function or array to transform values (optional) space: Number of spaces or string for indentation (optional) Basic Example JSON.stringify Example var obj = {Tutorial: "JavaScript", Version: "ES6", ...
Read MoreHow to convert MySQL DATETIME value to JSON format in JavaScript?
To convert MySQL DATETIME values to JSON format in JavaScript, you can parse the datetime string into a Date object and then use JSON.stringify() to convert it to JSON. This is useful when working with MySQL data in web applications. Understanding MySQL DATETIME Format MySQL DATETIME format is typically YYYY-MM-DD HH:MM:SS. JavaScript's Date constructor can parse various date formats, making conversion straightforward. Method 1: Converting to JSON Object with Individual Components This approach extracts individual date components and creates a structured JSON object: // Simulate MySQL DATETIME string var mySQLDateTime = new Date("2019-09-06 ...
Read MoreParsing JSON array with PHP foreach
In PHP, you can parse JSON arrays using json_decode() and iterate through them with foreach. The json_decode() function converts JSON strings into PHP arrays or objects. Syntax json_decode($json_string, $associative = false) Parameters Parameter Description $json_string The JSON string to decode $associative When true, returns associative array instead of object Example Here's how to parse a JSON array and access its nested values using foreach ? Output This will produce the following output ? 3490abc ...
Read MoreHow To Install and Configure MongoDB on CentOS 7
In this article, we will learn how to install and configure MongoDB on CentOS 7. MongoDB is an open-source NoSQL database that stores documents in a JSON-like format called BSON. Unlike traditional relational databases, MongoDB doesn't require a predefined schema and offers high availability, performance, and automatic scaling capabilities. Prerequisites CentOS 7 installed on the Linux machine A user with root privileges Adding the MongoDB Repository By default, the MongoDB repository is not available in CentOS 7. We need to add the MongoDB repository to the local machine first. vi /etc/yum.repos.d/mongodb-org.repo ...
Read MoreDifference between JSON and XML
Both JSON and XML are popular data interchange formats used to store and transfer structured data between systems. JSON is lightweight and commonly used in web APIs, while XML is more verbose but offers richer features like schemas and namespaces. Same Data in Both Formats Here is how the same student data looks in JSON and XML ? JSON Format { "student": { "name": "Alice", "age": 20, ...
Read MoreHow can we format a date using the Jackson library in Java?
Jackson is a Java-based library, and it can be useful to convert Java objects to JSON and JSON to Java objects. A Jackson API is faster than other API, needs less memory, and is good for large objects. We can format a date using the setDateFormat() of ObjectMapper class. This method can be used for configuring the default DateFormat when serializing time values as Strings and deserializing from JSON Strings. Syntax of setDateFormat() public ObjectMapper setDateFormat(DateFormat df) Here, df is the DateFormat instance to be used for formatting dates. Steps to format a date using Jackson in Java Following ...
Read More