# JsonTree getValue\<string\>() bug

**URL:** https://discourse.libcinder.org/t/jsontree-getvalue-string-bug/698
**Category:** Using Cinder
**Created:** [May 24, 2017, 3:54pm UTC](https://discourse.libcinder.org/t/jsontree-getvalue-string-bug/698 "2017-05-24T15:54:55Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Andrea](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/andrea/32/193_2.png) [@Andrea](https://discourse.libcinder.org/u/Andrea)
#### Post date: [May 24, 2017, 3:54pm UTC](https://discourse.libcinder.org/t/jsontree-getvalue-string-bug/698/1 "2017-05-24T15:54:55Z")

</div>

Hi,

I think there is a bug in the templated getValue() function.  
When the method is called with an std::string template and the string content includes blank spaces, the content is trimmed after the first blank space.

{  
“foo” : “Lorem ipsum dolor”  
}

this call returns "Lorem"  
fooJson.getValue\< string \>();

this call works just fine and returns "Lorem ipsum dolor"  
fooJson.getValue();

---

<div class="post-metadata">

### Author: ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)
#### Post date: [May 24, 2017, 11:37pm UTC](https://discourse.libcinder.org/t/jsontree-getvalue-string-bug/698/2 "2017-05-24T23:37:29Z")

</div>

`getValue<T>` effectively a wrapper around `boost::lexical_cast<T>`. Should check the boost docs to see if casting from a string to a string is expected to behave the way you’re seeing. There should probably be a specialization for `ci::fromString<T>` for strings that just returns the original value though, i think.

---

<div class="post-metadata">

### Author: ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)
#### Post date: [May 25, 2017, 6:02pm UTC](https://discourse.libcinder.org/t/jsontree-getvalue-string-bug/698/3 "2017-05-25T18:02:52Z")

</div>

Actually [this recent PR](https://github.com/cinder/Cinder/pull/1840) removed the use of `boost::lexical_cast`. What version of cinder are you using (if master git branch, what commit)?

Not sure if / how it could be related, but `JsonTree` does some initial string parsing to support a syntax like `data[foo.blah]`, maybe it is tripping up on the space in your value.

Probably also worth noting that we’re planning to deprecate `ci::JsonTree` in favor of just using jsoncpp directly. There’s little if any gain functionality wise in using cinder’s wrapper, it has some design issues, and requires boost containers, so we’d like to eventually remove it from the build.

---

<div class="post-metadata">

### Author: ![Andrea](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/andrea/32/193_2.png) [@Andrea](https://discourse.libcinder.org/u/Andrea)
#### Post date: [May 26, 2017, 10:37am UTC](https://discourse.libcinder.org/t/jsontree-getvalue-string-bug/698/4 "2017-05-26T10:37:09Z")

</div>

master branch latest commit.

---

<div class="post-metadata">

### Author: ![xumo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/xumo/32/75_2.png) [@xumo](https://discourse.libcinder.org/u/xumo)
#### Post date: [June 5, 2017, 10:52am UTC](https://discourse.libcinder.org/t/jsontree-getvalue-string-bug/698/5 "2017-06-05T10:52:59Z")

</div>

I see the same issue with XmlTree getting the value of a child.

`getValue<std::string>` and `getValue` returns the caracters before first blank.  
Thais is with or without using the CDATA wrapper.

---

<div class="post-metadata">

### Author: ![andrewfb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/andrewfb/32/2_2.png) [@andrewfb](https://discourse.libcinder.org/u/andrewfb)
#### Post date: [June 6, 2017, 6:22pm UTC](https://discourse.libcinder.org/t/jsontree-getvalue-string-bug/698/6 "2017-06-06T18:22:41Z")

</div>

@xumo - apologies for the delay; I missed this message. I Believe a recent commit should fix this issue. Please let us know if you see otherwise.
