let data=
[
{
system: {
id: '4gSSbjCFEorYXqrgDIP2FA',
type: 'Entry',
name: `Author`
},
DataDetails: {
shortSlugOption: {
"en-us":`some value`
},
mediaFileAssetLink: {
"za-op":`file Linl`
},
mediaFileAssetGalary: {
"hi":`file link 2`
},
singleMediaImage: {
"li-sd-op":`file link single`
},
}
},
{
system: {
id: '1aBOO8tu3lUsjtICuIbUM5',
type: 'Entry',
name: `Author`
},
DataDetails: {
short: {
"en-us":`details of shorts`
},
shortSlugOption: {
"hi-In":`options`
},
booleanField: {
"kl":`true`
}
}
},
{
system: {
id: '2pOUGnI1oRD7nsrYs600HA',
type: 'Entry',
name: `testing`
},
DataDetails: { testingNewValue: {
"en-uk":`details value`
} }
},
{
system: {
id: '66rzYr2BpWL1VTBHdLTdSW',
type: 'Entry',
name: `new`
},
DataDetails: { oneReference: {
"ru-re":`values 1`
}, multiReference: {
"uk-es":`values 2`
} }
},
{
system: {
id: 'cIb5mqEBRWDD6hrNmFmFE',
type: 'Entry',
name: `new`
},
DataDetails: { testingNewValue: {
"hi-IN":`jksdsdo`
} }
},
{
system: {
id: '7kRzyt4PFrX13gHcw3Z1Ko',
type: 'Entry',
name: `testing`
},
DataDetails: { testingNewValue: {
"en-us":`kknksdo`
} }
},
{
system: {
id: '2OspeCtNK0sh2cPiuU9jIz',
type: 'Entry',
name: `dummy`
},
DataDetails: {
short: {
"gh-we":`dfvndkssa`
},
shortSlugOption: {
"jk-cv":`sdocjosmdc`
},
mediaFileAssetLink: {
"en-us":`jdsojocis`
},
booleanField: {
"cb-af":`true`
}
}
},
{
system: {
id: '2eAmIIuG4xkLvatkU3RUSy',
type: 'Entry',
name: `dummy`
},
DataDetails: { dummy: {
"en-us":`dshcifdvk`
}, india: {
"kh-vh-we":`sdci`
} }
},
{
system: {
id: '7hbdS3MgfZ73TOtlu1WfXw',
type: 'Entry',
name: `dummy`
},
DataDetails: { testingNewValue: {
"ax-lo":`sdcoklsdc`
}, locationField: {
"sd-op":`sdcndkdc`
} }
}
];
data.map((value)=>{
var name = value.system.id;
var details={};
details[name]={
title:value.system.id,
uid:value.system.id,
url:`/${value.system.name}/${value.system.id}`,
}
console.log(details)
})
I am storing my data in JSON file but by doing some modification in my current object.
data I want to store in JSON is like in this way
{
"4gSSbjCFEorYXqrgDIP2FA": {
"title": "4gSSbjCFEorYXqrgDIP2FA",
"uid": "4gSSbjCFEorYXqrgDIP2FA",
"url": "/Author/4gSSbjCFEorYXqrgDIP2FA",
"shortSlugOption": "some value",
"mediaFileAssetLink": "file Linl"
},
"1aBOO8tu3lUsjtICuIbUM5": {
"title": "1aBOO8tu3lUsjtICuIbUM5",
"uid": "1aBOO8tu3lUsjtICuIbUM5",
"url": "/Author/1aBOO8tu3lUsjtICuIbUM5",
"short": "details of shorts",
"shortSlugOption": "options",
"booleanField": "true"
}
}
so to get entries from the Data object I have created map function to get the value and to fetch the DataDetails object I used Object.entries
for (const [key, value] of Object.entries(value.DataDetails)) {
console.log(`${key}: ${value}`);
}
so I made some changes in my code to get the desire output the problem is I am getting this
let data=
[
{
system: {
id: '4gSSbjCFEorYXqrgDIP2FA',
type: 'Entry',
name: `Author`
},
DataDetails: {
shortSlugOption: {
"en-us":`some value`
},
mediaFileAssetLink: {
"za-op":`file Linl`
},
mediaFileAssetGalary: {
"hi":`file link 2`
},
singleMediaImage: {
"li-sd-op":`file link single`
},
}
},
{
system: {
id: '1aBOO8tu3lUsjtICuIbUM5',
type: 'Entry',
name: `Author`
},
DataDetails: {
short: {
"en-us":`details of shorts`
},
shortSlugOption: {
"hi-In":`options`
},
booleanField: {
"kl":`true`
}
}
}
];
data.map((value)=>{
var name = value.system.id;
var details={};
for (const [key, values] of Object.entries(value.DataDetails)) {
details[name]={
title:value.system.id,
uid:value.system.id,
url:`/${value.system.name}/${value.system.id}`,
key:`${values}`
}
}
console.log(details)
})
I was trying to add ${key} but it's not making me to do so I can't get the DataDetails value as key in my object
is there any possible way I can DataDetails value which are shortSlugOption, mediaFileAssetLink by removing en-us,za-op n all
as my expected value is because the name field are common in this JSON object so I want to store common name field in One JSON file
{
"4gSSbjCFEorYXqrgDIP2FA": {
"title": "4gSSbjCFEorYXqrgDIP2FA",
"uid": "4gSSbjCFEorYXqrgDIP2FA",
"url": "/Author/4gSSbjCFEorYXqrgDIP2FA",
"shortSlugOption": "some value",
"mediaFileAssetLink": "file Linl"
},
"1aBOO8tu3lUsjtICuIbUM5": {
"title": "1aBOO8tu3lUsjtICuIbUM5",
"uid": "1aBOO8tu3lUsjtICuIbUM5",
"url": "/Author/1aBOO8tu3lUsjtICuIbUM5",
"short": "details of shorts",
"shortSlugOption": "options",
"booleanField": "true"
}
}