Parse Json File
A console application that reads in a json file using the an external module and prints a single known property value.
recipe.sml
The Recipe file that sets the standard name, type, version, as well as the single external dependency of the json11 project.
Name: 'Samples.Cpp.ParseJson'
Language: 'C++|0'
Version: 1.0.0
Type: 'Executable'
Dependencies: {
Runtime: [
'mwasplund|json11@1'
]
}
package-lock.sml
The package lock that was generated to capture the unique dependencies required to build this project.
Version: 5
Closures: {
Root: {
'C++': {
'Samples.Cpp.ParseJson': { Version: './', Build: 'Build0', Tool: 'Tool0' }
'mwasplund|json11': { Version: 1.1.5, Build: 'Build0', Tool: 'Tool0' }
}
}
Build0: {
Wren: {
'Soup|Cpp': { Version: 0.16.0 }
}
}
Tool0: {
'C++': {
'mwasplund|copy': { Version: 1.2.0 }
'mwasplund|mkdir': { Version: 1.2.0 }
'mwasplund|parse.modules': { Version: 1.2.0 }
}
}
}
message.json
A json file containing a single property containing a message for the application to print.
{
"message": "Hello!"
}
main.cpp
A simple main method that reads the contents of a single json file, parses the json content and prints a single message from a known property.
#include <fstream>
#include <iostream>
#include <streambuf>
#include <string>
import json11;
int main()
{
// Read in the contents of the json file
auto jsonFile = std::ifstream("./message.json");
auto jsonContent = std::string(
std::istreambuf_iterator<char>(jsonFile),
std::istreambuf_iterator<char>());
// Parse the json
std::string errorMessage;
auto json = json11::Json::parse(jsonContent, errorMessage);
// Print the single property value
std::cout << "Message: " << json["message"].string_value() << std::endl;
return 0;
}
.gitignore
A simple git ignore file to exclude all Soup build output.
out/