From my above comments ...
"There is no real complexity and the issue hardly has anything to do with JSON ... it all boils down to how to parse a specific value (here NC
) from a string (here "NC=test.com,O=xyz,L=uvw,C=AS"
)"
A straight forward parsing approach which covers exactly the custom schema of the values of domainDetails
respectively Requested
looks like this ...
Object
.fromEntries(
'NC=test.com,O=xyz,L=uvw,C=AS'
.split(',')
.map(customEntry => customEntry.split('='))
)['NC']
It split
s the string at any occurring comma. The result array gets map
ped into an array of key and value items by splitting each custom entry at the =
character.
The resulting array of entry-arrays then gets passed to Object.fromEntries
which creates an object where the OP finally can access the specific value the OP is looking for ... here by using the NC
-key.
The executable example code which takes the OP's data-structure into account will look like this ...
const responseData = {
notAfterTimeStamp: 123456787,
notBeforeTimeStamp: 123435637,
domainDetails: 'NC=test.com,O=xyz,L=uvw,C=AS',
Requested: 'CN=issuer Private Test CA ,OU=abc,OU=Testing',
};
const parsedResponseData = Object
.assign({}, responseData, {
domainDetails: Object.fromEntries(
responseData.domainDetails
.split(',')
.map(customEntry => customEntry.split('='))
)
});
const nc = parsedResponseData.domainDetails.NC
console.log({
responseData,
parsedResponseData,
nc,
});
.as-console-wrapper { min-height: 100%!important; top: 0; }