I have a string which contains multiple properties and sub-properties, which I would like to convert to a JSON object. The string I currently have is of this format:
"{"menuId":"1","menuItemDetails.itemDetailsId":"4","menuItemDetails.itemType.itemTypeId":"4","accessGroups":"","menuItemDetails.name":"","menuItemDetails.route":"","menuItemDetails.displayRule":"","menuItemDetails.continueMode":"","menuItemDetails.isSilent":"0","menuItemDetails.message.messageId":"26","menuItemDetails.title.messageId":"","menuItemDetails.defaultMessage.messageId":"","menuItemDetails.onSelect.messageId":"","menuItemDetails.action.actionId":"2","menuItemDetails.action.actionTypeId":"2","menuItemDetails.action.name":"GenerateViewMembersAction","menuItemDetails.action.fullyQualifiedName":"test.actions.sharedplans.GenerateViewMembersAction","menuItemDetails.action.plugin.pluginId":"1"}"
If I do a normal JSON.parse, I get an object like the following:
accessGroups
:
""
menuId
:
"1"
menuItemDetails.action.actionId
:
"2"
menuItemDetails.action.actionTypeId
:
"2"
menuItemDetails.action.fullyQualifiedName
:
"test.GenerateViewMembersAction"
menuItemDetails.action.name
:
"GenerateViewMembersAction"
I would like to group by propreties name, so I get the following:
{
menuId: 1
,menuItemDetails: {
action: {
actionId: 1
,actionTypeId: 2
...
}
,name: "GenerateView..."
}
}
Anyone can help me figure this out?
EDIT: To put things more into perspective, the case I have is a list of HTML elements, each having a name and a value, from which I want to build the JSON object. That does give me control over the JSON string, or allows me to create a JSON object directly if needed.