Home » Modeling » Epsilon » "EMC - JSON" for JSON object(JSON object as source for model-to-model transformation)
| | | | | | | | | | | |
Re: "EMC - JSON" for JSON object [message #1781450 is a reply to message #1781410] |
Wed, 07 February 2018 12:15 |
|
Hi Amir,
Given the approach to the JSON driver you will probably want to start with the XML driver[1]. In order to support allOfType, you will face the issue that JSON per se does not support the concept of "type", that is, it is impossible to tell (for all cases) if a key represents a type or an attribute, and for each attribute impossible to tell the type of the value:
{"widget": {
"debug": "on",
"window": {
...
}
is "widget" a type, so we can do:
rule GlossaryToClass
tranform g:Glossary
...
if so, then is window the name of an attribute and also a type?
This "concepts" are hard to generalise.
Perhaps what you want is to traverse the JSON model based on the JSON specification[2]. That is:
A JSON file/model has objects. An object has members, a member is a pair <name:value> where value can be a number, array, object, etc. And then the JSON model would know about "object", "pair", etc. types
Then you could do something like:
rule JsonObjectToClass
tranform jo:JsonObject
to emf:Class {
guard: jo.isTop() // Only transform root objects
...
For example the CSV model has the concept of row and field (column). If the CSV file has headers, then we can use this information to provide named fields. But that is about it.
Perhaps looking at how some of the JSON libraries provide support for instantiating Java classes from a JSON document can provide further guidance.
Cheers,
[1] https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/plugins/org.eclipse.epsilon.emc.plainxml/src/org/eclipse/epsilon/emc/plainxml/PlainXmlModel.java
[2] http://www.json.org
Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
|
|
|
Goto Forum:
Current Time: Thu Apr 25 06:33:56 GMT 2024
Powered by FUDForum. Page generated in 0.04276 seconds
|