There is a json code. Consisting by type: {"123":{...},"321":{...}} In it, you need to get "links" from each entry. I couldn't understand this note, please help me.
{
"3782474584475521065": {
"listingid": "3782474584475521065",
"price": 16,
"asset": {
"currency": 0,
"appid": 730,
"contextid": "2",
"id": "25996697315",
"amount": "1",
"market_actions": [
{
"link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D2354938592644984102",
"name": "Осмотреть в игре…"
}
]
}
},
"3782474584475520325": {
"listingid": "3782474584475520325",
"price": 16,
"asset": {
"currency": 0,
"appid": 730,
"contextid": "2",
"id": "25996698023",
"amount": "1",
"market_actions": [
{
"link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D9866835690490179400",
"name": "Осмотреть в игре…"
}
]
}
}
}
If I understood your question correctly, you need to extract the links from the json text. This is a solution:
const a = {
"3782474584475521065": {
listingid: "3782474584475521065",
price: 16,
asset: {
currency: 0,
appid: 730,
contextid: "2",
id: "25996697315",
amount: "1",
market_actions: [
{
link: "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D2354938592644984102",
name: "Осмотреть в игре…",
},
],
},
},
"3782474584475520325": {
listingid: "3782474584475520325",
price: 16,
asset: {
currency: 0,
appid: 730,
contextid: "2",
id: "25996698023",
amount: "1",
market_actions: [
{
link: "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D9866835690490179400",
name: "Осмотреть в игре…",
},
],
},
},
};
// get links from a
const links = Object.values(a).map(({ asset }) => {
const { market_actions } = asset;
const { link } = market_actions[0];
return link;
});
console.log(links);
This simply iterates through the object's values and accesses the link values through object extraction.
Return an array of objects {id:link}
const data = {
"3782474584475521065": {
"listingid": "3782474584475521065",
"price": 16,
"asset": {
"currency": 0,
"appid": 730,
"contextid": "2",
"id": "25996697315",
"amount": "1",
"market_actions": [
{
"link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D2354938592644984102",
"name": "Осмотреть в игре…"
}
]
}
},
"3782474584475520325": {
"listingid": "3782474584475520325",
"price": 16,
"asset": {
"currency": 0,
"appid": 730,
"contextid": "2",
"id": "25996698023",
"amount": "1",
"market_actions": [
{
"link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D9866835690490179400",
"name": "Осмотреть в игре…"
}
]
}
}
}
const result = Object.entries(data).map(([key, {asset, ...rest}]) => ({[key]: asset.market_actions[0].link}))
console.log(result)