What is the best way to extract the price value from the given Json object?

I've been struggling to extract the price value from this json object without success,

Is there anyone who could assist me? Thanks

{
   "Id":10069,
   "UrlHash":"3963aa68aac23b61ffc1275ad6e0f43d",
   "BrandId":1,
   "Name":"Nokia 8.3 5G",
   "Picture":"https://fdn2.gsmarena.com/vv/bigpic/nokia-83-5g.jpg",
   "ReleasedAt":"Released 2020, September 15",
   "Body":"220g, 9mm thickness",
   "Os":"Android 10, up to Android 11, Android One",
   "Storage":"64GB/128GB storage, microSDXC",
   "DisplaySize":"6.81\\\"",
   "DisplayResolution":"1080x2400 pixels",
   "CameraPixels":"64 MP         ",
   "VideoPixels":"2160p",
   "Ram":"6/8 GB RAM ",
   "Chipset":"Snapdragon 765G 5G",
   "BatterySize":"4500 mAh ",
   "BatteryType":"Li-Po",
   "Specifications":"{\\\"Technology\\\":\\\"GSM \\\\/ HSPA \\\\/ LTE \\\\/ 5G\\\",\\\"2G bands\\\":\\\"GSM 850 \\\\/ 900 \\\\/ 1800 \\\\/ 1900 - SIM 1 & SIM 2\\\",\\\"3G bands\\\":\\\"HSDPA 850 \\\\/ 900 \\\\/ 1700(AWS) \\\\/ 1900 \\\\/ 2100 \\\",\\\"4G bands\\\":\\\"1, 2, 3, 4, 5, 7, 8, 12, 13, 17, 20, 28, 32, 38, 39, 40, 41, 66, 71\\\",\\\"5G bands\\\":\\\"1, 2, 3, 5, 7, 8, 28, 38, 40, 41, 66, 71, 78 SA\\\\/NSA\\\",\\\"Speed\\\":\\\"HSPA 42.2\\\\/5.76 Mbps, LTE-A (4CA) Cat18 1200\\\\/150 Mbps, 5G 2.4\\\\/1.2 Gbps\\\",\\\"Announced\\\":\\\"2020, March 19\\\",\\\"Status\\\":\\\"Available. Released 2020, September 15\\\",\\\"Dimensions\\\":\\\"171.9 x 78.6 x 9 mm (6.77 x 3.09 x 0.35 in)\\\",\\\"Weight\\\":\\\"220 g (7.76 oz)\\\",\\\"SIM\\\":\\\"Single SIM (Nano-SIM) or Hybrid Dual SIM (Nano-SIM, dual stand-by)\\\",\\\"Type\\\":\\\"Li-Po 4500 mAh, non-removable\\\",\\\"Size\\\":\\\"6.81 inches, 112.0 cm2 (~82.9% screen-to-body ratio)\\\",\\\"Resolution\\\":\\\"1080 x 2400 pixels, 20:9 ratio (~386 ppi density)\\\",\\\"OS\\\":\\\"Android 10, upgradable to Android 11, Android One\\\",\\\"Chipset\\\":\\\"Qualcomm SM7250 Snapdragon 765G 5G (7 nm)\\\",\\\"CPU\\\":\\\"Octa-core (1x2.4 GHz Kryo 475 Prime & 1x2.2 GHz Kryo 475 Gold & 6x1.8 GHz Kryo 475 Silver)\\\",\\\"GPU\\\":\\\"Adreno 620\\\",...
   "DeletedAt":null,
   "CreatedAt":"2021-09-10T00:45:32",
   }

The PRICE property can be found within the Specifications section.

\"Price\":\"$ 433.90 \\/ € 574.35 \\/ £ 349.00\"

Answer №1

The element Specifications has undergone corruption. An attempt was made to escape the inch character ", which is present in the Quad and Single elements, but every instance of " within the JSON string has been escaped! This issue needs to be rectified at its source.

Below is the content of the Quad element within Specifications

\\\"Quad\\\":\\\"64 MP, f\\\\/1.9, (wide), 1\\\\/1.72\\\\\\\", 0.8\\\\u00b5m, PDAF\\\\r\\\\n  12 MP, f\\\\/2.2, 120\\\\u02da (ultrawide), 1\\\\/2.43\\\\\\\", 1.4\\\\u00b5m, AF\\\\r\\\\n  2 MP, (macro)\\\\r\\\\n  2 MP, (depth)\\\"

and here's what it should be:

"Quad":"64 MP, f/1.9, (wide), 1/1.72\\\", 0.8u00b5m, PDAFrn  12 MP, f/2.2, 120u02da (ultrawide), 1/2.43\\\", 1.4u00b5m, AFrn  2 MP, (macro)rn  2 MP, (depth)"

Additionally, the value of Specifications should not be enclosed in quotes.

"Specifications": {"Technology": "GSM / HSPA / LTE / 5G", ... },

It seems like someone is manually constructing JSON strings instead of utilizing a library. This serves as a clear example of why such practices should be avoided.

Answer №2

To extract the information from JSON, you can follow these steps:

try {
  const data: any = JSON.parse(YOUR_JSON_DATA_HERE);
  const price = data.Specs.Price;
  console.log("Price:", price);
} catch (error) {
  console.log(error);
}

If the data is in an array:

const price = dataArray[0].Specs.Price;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Extract Specific Data from JSON Response using Jquery?

How do I extract specific fields from this Json Result or response with the following structure? var WPQ3ListData = { "Row" : [{ "ID": "27", "PermMask": "0x400001f07fff1bff", "FSObjType": "0", "Title": "NOOO", "FileLeafRef": "27_.000", "Total ...

Applying a color gradient to nodes in d3 v5 based on their degree

If we were working with d3 v5, how might we go about coloring nodes based on their degrees? It's important that the visualization clearly shows nodes with higher degrees in darker shades and nodes with lower degrees in lighter shades. I attempted to ...

Expand the HTTP Response interface with Typescript

Recently, I've been working on a piece of code that involves the axios library. Here's what I have so far: const BTrustURLResponse: Response = await axios.get(`${process.env.BTRUST_URL}/flow/${process.env.BTRUST_FLOWID}/link?callback_url=${callba ...

Querying Objects in JavaScript

Is there a way to filter a JavaScript collection using a query syntax similar to SQL? I've come across one library that attempts to achieve this, called json-query. While it works in some scenarios, it does have its limitations. For example, queryin ...

What is the best way to create a single JSON object by extracting specific fields from real-time JSON data using Node.js?

The code below demonstrates how to retrieve JSON data from a specified URL using MQTT for publishing. The initial data is obtained from an HTTP source. var request = require('request'); var JSONStream = require('JSONStream'); var es = ...

Choosing a single random key-value pair from a specific attribute within a JSON schema

Is there a way to generate a new JSON schema based on the existing one, but with only one key-value pair chosen randomly from the "properties" attribute? The new schema should retain the "title" and "type" attributes as well. { "title": "animals object" ...

Handling Null Objects in NodeJs when Parsing JSON data

The server code is up and running smoothly const fs = require('fs'); const express = require('express'); const app = express(); app.get('/profile/:id', function (req, res) { // A route with a parameter ...

The binding of data in ng2-select encountered an error

Successfully implementing ng2-select to bind an array of objects to a dropdown. It worked seamlessly with an array of strings. private category: Array<object> = [{ "value": 1, "text": "Table" }, { "value": 2, "text": "Chair" }, { "value": 3, "text": ...

Enhance the functionality of 'takeWhile' by incorporating a limit parameter, similar to how 'take' operates

I am attempting to retrieve all pages until either there are no more pages or a certain limit (let's say 10 pages) is reached. If I follow this approach: obs.pipe(expand((page) => { return service.call(page).nextPage; }), take(10), takeWhil ...

When attempting to execute my script, I encountered an error message stating that "TypeError: puppeteer.use(...) is not

Here is the current code that I've been working on. After switching it to a new folder, I encountered an error that wasn't present before. I made sure to reinstall all the necessary modules in the package.json file, but the issue persists. Is the ...

Storing HTML values in a Meteor database is a common practice for web

Within my meteor project, I have a paragraph in HTML containing a JSON value as follows: {"Active Template Id":"6467","Shirt Brand":"levis","ProductId":"EB301","Brand":"on","Material":"cotton","Price":"1800","Combo Id":"S90"} I am looking to store this v ...

Using Angular2 to bind HTML markup to a boolean flag and trigger a method when the flag is set

I'm currently developing a solution for Angular 2 Bootstrap Datepicker to automatically close when a user clicks outside of it. My current approach involves tracking external clicks and updating a boolean flag as shown below: @Component({ select ...

I am looking to integrate my information into the user interface using Angular

import { Component, ViewEncapsulation } from '@angular/core'; import { Router } from '@angular/router'; import { Batch } from '../../../config/batchnew/batch.model'; import { BatchService } from '../../../config/batchnew ...

What is the best way to prevent styles.css in Angular from impacting all elements with the same selector?

Although I can align the content of my grid tiles, I only intended for it to affect the table that was inside a grid. This is what I have: .mat-grid-tile .mat-figure { justify-content: flex-start !important ; align-items: flex-start !important; } ...

Does a typescript module augmentation get exported by default when included in a component library?

Utilizing material-ui and Typescript, I developed a component library. By implementing Typescript module augmentation, I extended the theme options as outlined in their documentation on theme customization with Typescript. // createPalette.d.ts/* eslint-di ...

Setting default values for mat autocomplete is a useful feature for providing users with suggestions

Is it possible to display pre-selected values by default on auto complete when reloading the page? I have multiple auto completes on a page where users can select and save values. When the page is loaded again, I want the previously selected values to be d ...

update the value of a specific document in Firestore by specifying its

Is there a way to update document values in a Firestore collection for multiple records without manually specifying each document ID? Currently, I have a method that works for updating individual documents using their IDs, but what if I need to update a la ...

What is the best way to manage a key that may contain either an object or an array as its value?

In my current project, I am working on a piece of code that retrieves JSON data from a website. Here is an overview of what I am currently doing: $valueObject = array(); if (isset($decoded_json->NewDataSet)) { foreach ($decoded_json->Ne ...

Retrieving JSON data from a database in Laravel

One of the challenges I'm facing involves reading and outputting a JSON from a database. My approach to inserting a JSON looks something like this: $widget->settings = json_encode($input->get('settings')); Upon retrieval, I attempt t ...

Leveraging php arrays for database interrogation

I am attempting to query a MySQL database using values passed in an array. The issue I'm facing is that the first element produces two results instead of one. Below is the code snippet and the corresponding results. $common = array_intersect($ingredi ...