OSVR-Core
JSONHelpers.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_JSONHelpers_h_GUID_6DB9F077_A09D_44AB_C180_AABFE369637B
26 #define INCLUDED_JSONHelpers_h_GUID_6DB9F077_A09D_44AB_C180_AABFE369637B
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 #include <json/value.h>
33 #include <json/reader.h>
34 #include <json/writer.h>
35 
36 // Standard includes
37 #include <string>
38 
39 namespace osvr {
40 namespace common {
42  inline Json::Value jsonParse(std::string const &str) {
43  Json::Reader reader;
44  Json::Value val = Json::nullValue;
45  if (!reader.parse(str, val)) {
46  // in case the failed parse modified the value somehow
47  val = Json::nullValue;
48  }
49  return val;
50  }
51 
53  inline std::string jsonToCompactString(Json::Value const& val) {
54  Json::FastWriter writer;
55  return writer.write(val);
56  }
57 
60  inline std::string jsonToStyledString(Json::Value const& val) {
61  return val.toStyledString();
62  }
63 
64 } // namespace common
65 } // namespace osvr
66 
67 #endif // INCLUDED_JSONHelpers_h_GUID_6DB9F077_A09D_44AB_C180_AABFE369637B
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
std::string jsonToStyledString(Json::Value const &val)
Turns the JSON value into a pretty-printed, human-targeted string representation. ...
Definition: JSONHelpers.h:60
std::string jsonToCompactString(Json::Value const &val)
Turns the JSON value into a compact string representation.
Definition: JSONHelpers.h:53
Json::Value jsonParse(std::string const &str)
Parses a string as JSON, returning a null value if parsing fails.
Definition: JSONHelpers.h:42