- Notifications
You must be signed in to change notification settings - Fork1
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.
License
SubhenduShekhar/cjson
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation

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.
Tip
Please installCJSON plugin for language support in visual studio code
One of the strong feature which we have introduced is importing CJson/Json files in another CJson file.It works in the similar way, how we import libraries in programming languages. All you need to import it using$import "path/to/target/file"
anddeserialize
the file.
Unlike XPATH for XML files, we have JPATH for JSON files. But as the drawback of plain data files, we cannot refer any variable inside a json object to another variable. This feature is useful when you have to duplicate the json key, but the value will be pulled from another variable which is already present in the json file.
You can also refer to a variable which will be loaded after importing the file.
You can inject a variable dynamically also. Instead of replacing a variable value by parsing asgson
object, put a key in format<keyToBeReplaced>
like below:
{ "idValue": <id>}
Now create aHashMap
with key as<id>
and store relevant value in it.While invokinginject
function, pass the HashMap as the second parameter.
Injection can be performed single or bulk. Lets look at each one below:
Single injection can be performed by providing key and value to theinject()
.
inject(String key, Object value)
This function returnsdeserialized
class object.
Bulk injection can be performed by storing the injection data inDictionary
orHashMap
where key is thekey
where injection need to be performed andvalue
is the value.
inject(HashMap<String, Object>)
This function returnsdeserialized
class object.
CJSON also supportscommented lines by adding//
at the start of the line.
Please note, inline comments are not supported. Contributers create an issuehere
Parsing of CJSON string content is also possible now. You can create CJSON object with a second parameter(specific to language). For language specific details, refer below.
deserialize
is a function where CJSON content is compiled and converted into equivalent JSON content.Now, users can consume this content as a deserailized class object like any other parser works.
Refer toexample for language specific syntax.
User can consume converted JSON content toString
content too. Every language has a functiondeserializeAsString()
which converts compiles and converts CJSON to JSON content and returns JSON content in string format
Any JSON key value pair can be removed by providing its JPath.Please Note, if you useremove
beforedeserialize
you will receiveUndeserializedCJSON
exception.
This is because, unless the content is deserialized, CJSON engine has not processed the CJSON content.
This function returns deserialized class object post removal.
Here are the examples
Single removal can be performed by simply providing the JPath as parameters.
Bulk removal acceptsList<String> JPaths
to perform removal.
Any Java object can be converted to json string by usingtoString()
function.
It accepts pure java object and returns JSON in string.
Here are the examples
This function finds the value of the provided JPath as parameter. This function returnsObject
type data.So a type cast will be required to unlock native functions.
Returns all possibleJPaths
inside JSON.
Returns all values to all possibleJPaths
inside JSON. Before executing this function, you need call for getting all possible keys function.
This function validates whether the provided string is JSON content or not.
Unline XPath in xml format, JSON has JPath format. THe difference is, instead of//
or/
, JPath starts with$.
Below is an example:
$.path.to.variables
If any array is encountered, below is the way index is provided:
$.path.to.array[index].variable
Keywords | Description |
---|---|
$import | To import other json file |
$.jpath | Refer to a local variable inside JSON |
Comments(Single/ Multi-line) | // |
<key> | Expects a dynamic variable |
About
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.