CJSON is a data file format(inspired from JSON), but supports logical expressions too. Having extended language support to NodeJS, Python, Java and DotNet, users has experienced data reusability. For features and examples, please refer to this documentation as base document.
PLEASE NOTE, ONLY DOTNET V6.0 IS SUPPORTED
dotnet add package CJson --version 1.0.0
NuGet\Install-Package CJson -Version 1.0.0
<PackageReference Include="CJson" Version="1.0.0" />
paket add CJson --version 1.0.0
#r "nuget: CJson, 1.0.0"
// Install CJson as a Cake Addin
#addin nuget:?package=CJson&version=1.0.0
// Install CJson as a Cake Tool
#tool nuget:?package=CJson&version=1.0.0
{
"source": $import "path/to/source.json",
"target": {
"fruit": "Apple",
"size": "Large",
"color": "Red"
}
}
using CJson;
namespace CJsonImpl {
public class Main {
public static void Main(String[] args) {
CJson.Path cjsonFilePath = new CJson.Path(GetCurrentDirectory, "file.cjson")
CJson<SerializableClass> cJson = new CJson<SerializableClass>(cjsonFilePath);
SerializableClass classObj = cJson.Deserialize();
}
}
}
{
"source": {
// source.json content
},
"target": {
"fruit": "Apple",
"size": "Large",
"color": "Red"
}
}
Below example shows color
variable is calling data from fruit
variable
{
"target": {
"fruit": "Orange",
"size": "Medium",
"color": $.target.fruit
}
}
using CJson;
namespace CJsonImpl {
public class Main {
public static void Main(String[] args) {
CJson.Path cjsonFilePath = new CJson.Path(GetCurrentDirectory, "file.cjson")
CJson<SerializableClass> cJson = new CJson<SerializableClass>(cjsonFilePath);
SerializableClass classObj = cJson.Deserialize();
}
}
}
{
"target": {
"fruit": "Orange",
"size": "Medium",
"color": "Orange"
}
}
{
"target": {
"fruit": "Orange",
"size": "Medium",
"color": "Orangle",
"sellerId": <id>
}
}
using CJson;
namespace CJsonImpl {
public class Main {
public static void Main(String[] args) {
Dictionary<String, String> data = new Dictionary<String, String>();
data.Add("id", "ID01");
CJson<SerializableClass> cJson = new CJson<SerializableClass>(new Path("file/path/to/file.cjson"));
SerializableClass target = cJson.Inject(data);
}
}
}
{
"target": {
"fruit": "Orange",
"size": "Medium",
"color": "Orangle",
"sellerId": "ID01"
}
}
For single line comments, use //
For multi line comments, use like below:
// This is first line comment
// This is the second one
{
"name": "Amrut" // This is not allowed
}
Any import path used must be absolute. Otherwise, you will receive AbsolutePathConstraintError
exception
using CJson;
namespace CJsonImpl {
public class Main {
public static void Main(String[] args) {
String cjsonContent = "{\n" +
" \"source\": $import \"" + pureJsonfilePath.ToString + "\",\n" +
" \"target\": {\n" +
" \"fruit\": \"Apple\",\n" +
" \"size\": \"Large\",\n" +
" \"color\": \"Red\"\n" +
" }\n" +
"}";
CJson<SerializableClass> cJson = new CJson<SerializableClass>(cjsonContent);
SerializableClass target = cJson.Deserialize();
}
}
}
using CJson;
namespace CJsonImpl {
public class Main {
public static void Main(String[] args) {
Target target = new Target();
target.source = new Pure();
target.source.quiz = new HashMap<>();
Dictionary<String, Questions> questionsHashMap = new Dictionary<String, Questions>();
Questions questions = new Questions();
questions.question = "Which one is correct team name in NBA?";
questions.options = Arrays.asList("New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket");
questions.answer = "Huston Rocket";
questionsHashMap.put("q1", questions);
target.source.quiz.put("sport", questionsHashMap);
String targetString = CJson<Object>.ToString(target);
}
}
}
{
"source":{
"quiz":{
"sport":{
"q1":{
"question":"Which one is correct team name in NBA?",
"options":[
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer":"Huston Rocket"
},
"q2":null
}
}
}
}