Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #1486
Closed
Open
Issue created Feb 01, 2021 by jshep321@jshep321

Wildcard filter: remove empty objects

Hi, I wrote a sample .ino to demonstrate the challenge from https://github.com/bblanchon/ArduinoJson/issues/1309 with descriptions in the serial printout. File is here: https://gist.github.com/jshep321/2b9ffb745edfa9dc121257656d811a07

Note that for the json format I would prefer an array for the "data" level, but the Google cloud database converts arrays to object automatically, so I'm a bit out of luck without restructuring the data or starting elsewhere!

Output from the program:

-----------initial json input string: -----------
{"USER1": { "data" : { "1" : "item 1 description", "2" : "item 2 description"}, "associated user data" : "value"}, "USER2": { "data" : { "10" : "item 10 description", "11" : "item 11 description"} ,"associated user data" : "value"}}
-----------fullUserDB after prettify (no filter yet): -----------
{
  "USER1": {
    "data": {
      "1": "item 1 description",
      "2": "item 2 description"
    },
    "associated user data": "value"
  },
  "USER2": {
    "data": {
      "10": "item 10 description",
      "11": "item 11 description"
    },
    "associated user data": "value"
  }
}
make a filter -- 
ideally I want to keep the target data of "10" and associated higher levels only 
--> { USER2, data : { 10 : item 10 description }, associated user data: value } <--
Filter: 
filter["*"]["data"]["10"] = true
-----------filtered userDB after pretty+filter: -----------
{
  "USER1": {
    "data": {}
  },
  "USER2": {
    "data": {
      "10": "item 10 description"
    }
  }
}
Result: Keeping unwanted USER1 and truncated wanted associated user data

Help appreciated or else I might have to do wonky stuff to search and filter this json object.

Thanks!

Assignee
Assign to
Time tracking