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

Can't extract from nested JSON #1730

Closed
nicksterious opened this issue Mar 18, 2022 · 2 comments
Closed

Can't extract from nested JSON #1730

nicksterious opened this issue Mar 18, 2022 · 2 comments
Labels
bug v6 ArduinoJson 6

Comments

@nicksterious
Copy link

Describe the bug
I am getting a compile error when trying to extract a portion of a nested JSON document.

Troubleshooter report
Here is the report generated by the ArduinoJson Troubleshooter:

ArduinoJson Troubleshooter's report
  1. The issue happens at compile time
  2. The error is not in the list

Environment
Here is the environment that I used:

  • Microcontroller: RP2040
  • Core/runtime: arduino mbed
  • IDE: VSCode/platformio

Reproduction
Here is a small snippet that reproduces the issue.

{
  "state": {
    "desired": {
      "welcome": "aws-iot",
      "powerState": "OFF"
    },
    "reported": {
      "welcome": "aws-iot",
      "powerState": "OFF"
    }
  },
  "metadata": {
    "desired": {
      "welcome": {
        "timestamp": 1647421659
      },
      "powerState": {
        "timestamp": 1647594171
      }
    },
    "reported": {
      "welcome": {
        "timestamp": 1647421659
      },
      "powerState": {
        "timestamp": 1647594576
      }
    }
  },
  "version": 531,
  "timestamp": 1647620956
}
  DynamicJsonDocument incoming_message(2048);
  DynamicJsonDocument thing_state(2048);
  deserializeJson(incoming_message, incoming_message_str);
  thing_state = incoming_message["state"];
  // at this point thing_state should contain the "state" but not the "metadata"

Compiler output

.pio\libdeps\pico\ArduinoJson\src/ArduinoJson/Document/BasicJsonDocument.hpp:100:31: error: 'const class ArduinoJson6193_F1::MemberProxy<ArduinoJson6193_F1::JsonDocument&, const char*>' has no member named 'memoryUsage'
  100 |     size_t requiredSize = src.memoryUsage();
      |                           ~~~~^~~~~~~~~~~
*** [.pio\build\pico\src\main.cpp.o] Error 1

Expected output:
Program should compile and maybe work.

@bblanchon
Copy link
Owner

Hi @nicksterious,

Thank you very much for reporting this bug.
I'm going to fix it soon; meanwhile, please use the following workaround:

thing_state = incoming_message["state"].as<JsonVariant>();

Best regards,
Benoit

@bblanchon
Copy link
Owner

The fix was released with ArduinoJson 6.19.4.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2022
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants