"EMC - JSON" for JSON object [message #1779944] |
Mon, 15 January 2018 19:22  |
Eclipse User |
|
|
|
Hi all,
What is be the best approach if the source of a model-to-model transformation is JSON object (Java object)?
As far as I understand, I can use EMC - JSON form Epsilon Lab to read a JSON Document.
Let me shortly describe my application scenario:
The input of the transformation would be an object (JSON). After parsing data from JSON into Java, I would like to transform it using ETL. The target model for the transformation would be available as EMF model.
Any suggestions?
Many thanks,
Amir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: "EMC - JSON" for JSON object [message #1781450 is a reply to message #1781410] |
Wed, 07 February 2018 07:15  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04612 seconds