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

v7 equivalent of validateJson #2090

Closed
higaski opened this issue May 14, 2024 · 2 comments
Closed

v7 equivalent of validateJson #2090

higaski opened this issue May 14, 2024 · 2 comments
Labels
question v7 ArduinoJson 7

Comments

@higaski
Copy link

higaski commented May 14, 2024

The v6 documentation contains a small validateJson snippet which I have always found immensely useful:

bool validateJson(const char* input) {
  StaticJsonDocument<0> doc, filter;
  return deserializeJson(doc, input, DeserializationOption::Filter(filter)) == DeserializationError::Ok;
}

Now, the v7 documentation contains an equivalent snippet, but I've red that Static- and DynamicJsonDocument got merged into a single class which now always allocates in 1kB blocks. Does this mean that validateJson now allocates 2x1kB?

bool validateJson(const char* input) {
  JsonDocument doc, filter;
  return deserializeJson(doc, input, DeserializationOption::Filter(filter)) == DeserializationError::Ok;
}
@bblanchon
Copy link
Owner

Hi @higaski,

The current implementation allocates the memory pools lazily, so an empty JsonDocument doesn't require any heap allocation.

You can confirm that by replacing the allocator:
https://wandbox.org/permlink/p07bfdAXL9johHby

Best regards,
Benoit

@bblanchon bblanchon added the v7 ArduinoJson 7 label May 15, 2024
@higaski
Copy link
Author

higaski commented May 15, 2024

Thanks for clearing that up!

@higaski higaski closed this as completed May 15, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question v7 ArduinoJson 7
Projects
None yet
Development

No branches or pull requests

2 participants