Skip to content

CSEmbree/cppjsongenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

CppJSONGenerator


README Content is broken up as follows:

  1. PURPOSE
  2. INSTALL
  3. BASIC USE
  4. DEPENDANCIES
  5. EXAMPLE
  6. REFERENCES
  7. TODO

1. PURPOSE


The purpose of cppjsongenerator is to generate SMALL amounts of JSON output using a C++ object.

For the duration of this document, the variable $CPPJSONGENERATOR refers to the installation/download location of the cppjsongenerator git repository on your machine.

Questions, comments, or bugs should be reported to: cse@cameronembree.com


2. INSTALL


Inlcude files from the $CPPJSONGENERATOR/src to your source code directory. Create an instance of the cppjsongenerator object and use it as instructed in the 3. BASIC USE section.


3. BASIC USE


After including the cppjsongenerator class in your build path, create and instance of it and use it as you would expect. For example, the following code:

  string fileName = "json_example.txt";
  json_generator jg( fileName );

  jg.open_object();                          //{                                                                                 

  jg.add_pair("title","Example Schema");     //  "title": "Example Schema",                                                      
  jg.add_pair("type","object");              //  "type": "object",                                                               

  jg.open_object("properties");              //  "properties": {                                                                 

  jg.open_object("firstName");               //    "firstName": {                                                                
  jg.add_pair("type","string");              //      "type": "string"                                                            
  jg.close_object();                         //    },                                                                            

  jg.open_object("lastName");                //    "lastName": {                                                                 
  jg.add_pair("type","string");              //      "type": "string"                                                            
  jg.close_object();                         //    }                                                                             

  jg.open_object("age");                     //    "age": {                                                                      
  jg.add_pair("description","Age in years"); //      "description": "Age in years",                                              
  jg.add_pair("type","integer");             //      "type": "integer",                                                          
  jg.add_pair("minimum",0);                  //      "minimum": 0                                                                
  jg.close_object();                         //    }                                                                             
  jg.close_object();                         //  },                                                                              

  // vectors are used to represent arrays
  std::vector<string > requiredFields;
  requiredFields.push_back("firstName");
  requiredFields.push_back("lastName");
  jg.add_pair("required", requiredFields);   //  "required": ["firstName", "lastName"]                                           

  jg.close_object();                         //} 

generates the following JSON output as a file called example.txt

{
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
}

Additonal examples of using cppjsongenerator can be found in the 5. EXAMPLE section


4. DEPENDANCIES


This library only uses standard c++ libraries.


5. EXAMPLE


Multple examples of how to use this library can be found in

$cppjsongenerator/tests

6. REFERENCES


JSON format generation rules implimented by the design here:

http://www.w3schools.com/json/json_syntax.asp

The example in the 3. Basic Use section was borrowed from:

http://json-schema.org/examples.html

JSON generated by cppjsongenerator were validated with:

http://jsonlint.com/


7. TODO


  • Finish basic design
  • Choose testing environment for cppjsongenerator. Use GoogleTest?
  • Create Unit tests for cppjsongenerator.cpp

About

personal manual json generator in cpp - VERY in development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published