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
  • #763
Closed
Open
Issue created Jun 23, 2018 by Administrator@rootContributor

Unable to test key `is<String>()`

Created by: sticilface

I'm trying to use some templated functions to retrieve values from a JsonObject see below

template<typename T>
bool parse(const __FlashStringHelper * key, JsonObject & root, T & dest)
{
	if (root.containsKey(key) && root[key].is<T>()) {
		dest = root.get<T>(key);
		return true; 
	} else {
		return false;
	}
}

and i've discovered that you cannot test a Key for being a String. I know you can test for const char * instead but as in my first example it has to be templated so i cannot use const char * when passing String in...

here is a minimal sketch

#include <ArduinoJson.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200); 
  DynamicJsonBuffer buffer;
  JsonObject & root = buffer.createObject();
  String myString = "hello"; 
  root["test"] = myString; 

  if (root["test"].is<String>()) {
    Serial.println("root is String"); 
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

I know String is not included in the list of types you can test for using is<T>(). is there a specific reason for this?

Cheers

Assignee
Assign to
Time tracking