Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot unflatten json object #4349

Open
2 tasks
aka-mj opened this issue Apr 15, 2024 · 2 comments
Open
2 tasks

Cannot unflatten json object #4349

aka-mj opened this issue Apr 15, 2024 · 2 comments
Labels
solution: invalid the issue is not related to the library

Comments

@aka-mj
Copy link

aka-mj commented Apr 15, 2024

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

@nlohmann
Copy link
Owner

Your JSON value does not satisfy the requirements for unflatten, see https://json.nlohmann.me/api/basic_json/unflatten/

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug labels Apr 15, 2024
@nlohmann
Copy link
Owner

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
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants