JSON library based on JSMN lib

Dependents:   ATT_WNCInterface_Info WNCInterface_HTTP_example NerfUS-Coord Mbed_Prototype_copy_4_INNO_day_15_6_2017 ... more

C++ JSON wrapper over JSMN lib (https://github.com/zserge/jsmn).

This C++ Class is a set of common tools/procedures as a C++ wrapper over JSMN JSON parser library. It is intended to provide the boiler-plate code, with intentions to reduce code clutter, in more of C++ fashion.

In contrast to original library, Json is intended to work strictly with valid JSON structures. Non-standard JSON structures should result in an error.

This class works explicitly on the indices returned by underlying JSMN library. In the scope of this class, its function parameters, return types, and documentation, the term 'index' will always mean the index of JSMN tokens, parsed by the Json constructor, unless and until explicitly mentioned otherwise.

Revision:
4:ae34010d87e5
Parent:
3:fab591fca1e7
Child:
5:dd98cf00ed9b
--- a/Json.h	Thu Jun 02 06:08:24 2016 +0000
+++ b/Json.h	Tue Aug 02 20:21:04 2016 +0000
@@ -29,6 +29,7 @@
         Json ( const char * jsonString, size_t length );
         virtual ~Json ();
 
+        int findKeyIndex ( const char * key, const int &startingAt ) const;
         int findKeyIndexIn ( const char * key, const int &parentIndex ) const;
         int findChildIndexOf ( const int &parentIndex, const int &startingAt ) const;
         bool matches ( const int & tokenIndex, const char * value ) const;
@@ -46,6 +47,8 @@
         inline bool tokenBooleanValue ( const int tokenIndex ) const;
 
         // void print () const;
+        
+        static char * unescape ( char * jsonString );
 };
 
 inline bool Json::isValidJson () const
@@ -78,5 +81,14 @@
     return source + tokens [ tokenIndex ].start;
 }
 
+inline bool Json::tokenBooleanValue ( const int tokenIndex ) const
+{
+    if ( type ( tokenIndex ) == JSMN_PRIMITIVE )
+    {
+        return matches ( tokenIndex, "true" );
+    }
+    return false;
+}
+
 #endif