First of all, you need to decide where you want to extract the data from.
If it is from a file you need to import the file with for example the npm package 'fs'.
Example code:
const fs = require("fs");
const content = fs.readFileSync("content.json");
console.log("Output: \n" + content);
You can use axios to get the json data from a specific url. For example:
axios.get('yoururl')
.then((response) => {
// handle success
console.log(response);
})
.catch((error) => {
// handle error
console.log(error);
});
Then you have extracted the data successfully.
After that you can parse the json content with JSON.parse and that will return an object with all its content.
For example for your code:
const json = `{"order": {
"PRD_SHIRT_048": {
"price": "40.99",
"productId": "PRD_SHIRT_048",
"quantity": "1"
},
"PRD_TOP_047": {
"price": "40.99",
"productId": "PRD_TOP_047",
"quantity": "1"
}
}}`;
const obj = JSON.parse(json);
console.log(obj.order.PRD_SHIRT_048.productId);
If you want, you can iterate over the objects from the order object and get the product id from that.