arduino-libraries / Arduino_JSON

Official JSON Library for Arduino
GNU Lesser General Public License v2.1
151 stars 60 forks source link

Added Simple Filtering and Property Comparison #32

Closed Phando closed 2 years ago

Phando commented 2 years ago

This PR introduces two new functions (and their overloads).

  bool hasPropertyEqual(const char* key,  const char* value) const;  
  bool hasPropertyEqual(const char* key,  const JSONVar& value) const;  
  bool hasPropertyEqual(const String& key,  const String& value) const;  
  bool hasPropertyEqual(const String& key,  const JSONVar& value) const;  

  JSONVar filter(const char* key, const char* value) const;
  JSONVar filter(const char* key, const JSONVar& value) const;
  JSONVar filter(const String& key, const String& value) const;
  JSONVar filter(const String& key, const JSONVar& value) const;

hasPropertyEqual returns true if the JSONVar has a property with a value that matches value.

filter returns an array containing all the objects who have a property matching value. If an object and not an array is passed to filter and there is a match, the original object is returned inside an array.

This PR should cut down on repetitive JSONVar parsing code.

CLAassistant commented 2 years ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Joe Andolina seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

github-actions[bot] commented 2 years ago

Memory usage change @ 1da99788176f26ed6db2a97e88a8038597b7da2b

Board flash % RAM for global variables %
arduino:avr:leonardo 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:mega 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:nano 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:yun 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_edge:edge_control 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nano33ble 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m4 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:megaavr:nona4809 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:megaavr:uno2018 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg 0 - 0 0.0 - 0.0 N/A N/A
arduino:samd:arduino_zero_edbg 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrzero 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table Board|examples/JSONArray
flash|%|examples/JSONArray
RAM for global variables|%|examples/JSONKitchenSink
flash|%|examples/JSONKitchenSink
RAM for global variables|%|examples/JSONObject
flash|%|examples/JSONObject
RAM for global variables|% -|-|-|-|-|-|-|-|-|-|-|-|- arduino:avr:leonardo|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:avr:mega|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:avr:nano|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:avr:yun|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:mbed_edge:edge_control|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:mbed_nano:nano33ble|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:mbed_nano:nanorp2040connect|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:mbed_portenta:envie_m4|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:mbed_portenta:envie_m7|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:megaavr:nona4809|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:megaavr:uno2018|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:sam:arduino_due_x_dbg|0|0.0|N/A|N/A|0|0.0|N/A|N/A|0|0.0|N/A|N/A arduino:samd:arduino_zero_edbg|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:samd:mkrzero|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 arduino:samd:nano_33_iot|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0
Click for full report CSV ``` Board,examples/JSONArray
flash,%,examples/JSONArray
RAM for global variables,%,examples/JSONKitchenSink
flash,%,examples/JSONKitchenSink
RAM for global variables,%,examples/JSONObject
flash,%,examples/JSONObject
RAM for global variables,% arduino:avr:leonardo,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:avr:mega,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:avr:nano,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:avr:yun,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:mbed_edge:edge_control,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:mbed_nano:nano33ble,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:mbed_portenta:envie_m4,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:mbed_portenta:envie_m7,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:megaavr:nona4809,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:megaavr:uno2018,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:sam:arduino_due_x_dbg,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A arduino:samd:arduino_zero_edbg,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:samd:mkrzero,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:samd:nano_33_iot,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 ```