Cannot unflatten json object
aka-mj opened this issue · comments
Michael John commented
Description
I have a flattened object that I then want to unflatten but get the following error instead:
libc++abi: terminating with uncaught exception of type nlohmann::json_abi_v3_11_3::detail::type_error: [json.exception.type_error.315] values in object must be primitive
Reproduction steps
call unflatten() on a flatten json object.
Expected vs. actual results
{"SettingsRequest":{
"ApplicationError":["1","No ACK","2","No ACK","3","No ACK","4","No ACK"],
"DateAppliedOnDevice":"2024-04-15T09:29:25Z",
"DateToExecuteOnDevice":"2022-08-04T17:01:39.645090001Z",
"DeviceId":"12345",
"SettingsPayloadId":34,
"SettingsValues":null
}}
libc++abi: terminating with uncaught exception of type nlohmann::json_abi_v3_11_3::detail::type_error: [json.exception.type_error.315] values in object must be primitive
Minimal code example
No response
Error messages
No response
Compiler and operating system
clang 13, linux
Library version
3.11.3
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.
Niels Lohmann commented
Your JSON value does not satisfy the requirements for unflatten, see https://json.nlohmann.me/api/basic_json/unflatten/
Niels Lohmann commented
The flattened version of your JSON value would be
{
"/SettingsRequest/ApplicationError/0": "1",
"/SettingsRequest/ApplicationError/1": "No ACK",
"/SettingsRequest/ApplicationError/2": "2",
"/SettingsRequest/ApplicationError/3": "No ACK",
"/SettingsRequest/ApplicationError/4": "3",
"/SettingsRequest/ApplicationError/5": "No ACK",
"/SettingsRequest/ApplicationError/6": "4",
"/SettingsRequest/ApplicationError/7": "No ACK",
"/SettingsRequest/DateAppliedOnDevice": "2024-04-15T09:29:25Z",
"/SettingsRequest/DateToExecuteOnDevice": "2022-08-04T17:01:39.645090001Z",
"/SettingsRequest/DeviceId": "12345",
"/SettingsRequest/SettingsPayloadId": 34,
"/SettingsRequest/SettingsValues": null
}
With this value, unflatten
does work which yields
{
"SettingsRequest": {
"ApplicationError": [
"1",
"No ACK",
"2",
"No ACK",
"3",
"No ACK",
"4",
"No ACK"
],
"DateAppliedOnDevice": "2024-04-15T09:29:25Z",
"DateToExecuteOnDevice": "2022-08-04T17:01:39.645090001Z",
"DeviceId": "12345",
"SettingsPayloadId": 34,
"SettingsValues": null
}
}