Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » "EMC - JSON" for JSON object(JSON object as source for model-to-model transformation)
"EMC - JSON" for JSON object [message #1779944] Tue, 16 January 2018 00:22 Go to next message
Amir Kanan is currently offline Amir KananFriend
Messages: 22
Registered: July 2017
Junior Member
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 #1779995 is a reply to message #1779944] Tue, 16 January 2018 12:47 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 195
Registered: October 2009
Location: UK
Senior Member

Hi Amir,

If you parse the JSON to Java, then the input to the ETL transformation would be a Java model, in that case you will need to use the Java EMC[1].

Cheers,

[1] https://github.com/epsilonlabs/emc-jdt


Horacio Hoyos Rodriguez
Epsilon Committer
Research Assistant
University Of York
Re: "EMC - JSON" for JSON object [message #1780048 is a reply to message #1779995] Tue, 16 January 2018 19:35 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1532
Registered: July 2009
Location: York, UK
Senior Member

Hi both,

The JDT driver is unlikely to help with this as its aim is to expose Java code (not instances of Java classes) as an Epsilon-compatible model. The JSON driver [1] sounds like a better fit but it lacks documentation at the moment.

Cheers,
Dimitris

[1] https://github.com/epsilonlabs/emc-json
Re: "EMC - JSON" for JSON object [message #1780057 is a reply to message #1780048] Tue, 16 January 2018 23:05 Go to previous messageGo to next message
Amir Kanan is currently offline Amir KananFriend
Messages: 22
Registered: July 2017
Junior Member
Hi Both,

Thanks for your quick respond. I will try to read the JSON driver code and if I had any question then I will ask it under the same topic.

Regards,
Amir
Re: "EMC - JSON" for JSON object [message #1781152 is a reply to message #1780057] Fri, 02 February 2018 06:19 Go to previous messageGo to next message
Amir Kanan is currently offline Amir KananFriend
Messages: 22
Registered: July 2017
Junior Member
Hi,

I am reviewing the JSON driver code now. I need your help to understand the following EOL code:

M.root[0].e_commit.e_author.a_name.println();


Please look at the line 54 of the following page:
https://github.com/epsilonlabs/emc-json/blob/master/org.eclipse.epsilon.emc.json/src/org/eclipse/epsilon/emc/json/JsonModel.java

What is the purpose of those prefixes in the EOL code? - I guess, they used for Querying and modifying.
How can I use them?
Is there any tutorial for scripting JSON documents with EOL?

Many thanks,
Amir
Re: "EMC - JSON" for JSON object [message #1781163 is a reply to message #1781152] Fri, 02 February 2018 08:44 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1532
Registered: July 2009
Location: York, UK
Senior Member

Hi Amir,

There's not much documentation for the driver but the rationale for the prefixes is the same as with the XML driver (see [1]).

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/plain-xml/
Re: "EMC - JSON" for JSON object [message #1781248 is a reply to message #1781163] Mon, 05 February 2018 01:04 Go to previous messageGo to next message
Amir Kanan is currently offline Amir KananFriend
Messages: 22
Registered: July 2017
Junior Member
Hi Dimitris,

Thanks, I will review that article.

Regards,
Amir
Re: "EMC - JSON" for JSON object [message #1781252 is a reply to message #1781248] Mon, 05 February 2018 06:38 Go to previous messageGo to next message
Amir Kanan is currently offline Amir KananFriend
Messages: 22
Registered: July 2017
Junior Member
Hi Dimitris,

I would like to use the JSON file [1] located in EMC - JSON as the source model for a M2M transformation (JSON to EMF). I have a bit difficulty to write my ETL.

Let me describe my problem:

I am aware that the ! character is used to separate the name of the type from the name of the model it is defined in.

The source model would be the JSON model [1] as I have described above. Therefore, the model name would be "M" (defined in JsonModel.java). However, I was wondering what are the type names.

Regards,
Amir

[1] https://github.com/epsilonlabs/emc-json/blob/master/org.eclipse.epsilon.emc.json/commits.json
Re: "EMC - JSON" for JSON object [message #1781262 is a reply to message #1781252] Mon, 05 February 2018 09:11 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1532
Registered: July 2009
Location: York, UK
Senior Member

Hi Amir,

getAllOfTypeFromModel has not been implemented yet [1] so the only way JSON documents can be queried at the moment is through their root as shown in [2]. Clearly, the JSON driver is far from complete and any contributions would be more than welcome.

Cheers,
Dimitris

[1] https://github.com/epsilonlabs/emc-json/blob/master/org.eclipse.epsilon.emc.json/src/org/eclipse/epsilon/emc/json/JsonModel.java#L168
[2] https://github.com/epsilonlabs/emc-json/blob/master/org.eclipse.epsilon.emc.json/src/org/eclipse/epsilon/emc/json/JsonModel.java#L54
Re: "EMC - JSON" for JSON object [message #1781267 is a reply to message #1781262] Mon, 05 February 2018 10:20 Go to previous messageGo to next message
Amir Kanan is currently offline Amir KananFriend
Messages: 22
Registered: July 2017
Junior Member
Hi Dimitris,

Many thanks for the prompt reply.

Can I execute a m2m transformation as following instead?

rule Json2EMF
transform m : M.root[0].e_commit.e_author
to n : Tree!Tree

{

m.name = n.name1;
m.email = n.mail;
m.date = n.dateTime;

}

Or is it not possible to do any transformation at this stage when parsing a JSON model with EMC - JSON ?

Thanks for your attention. I'm looking forward to your reply.

Regards,
Amir
Re: "EMC - JSON" for JSON object [message #1781273 is a reply to message #1781267] Mon, 05 February 2018 12:01 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1532
Registered: July 2009
Location: York, UK
Senior Member

Hi Amir,

In the absence of support for types in the JSON driver, I don't think it's possible to use ETL for transforming JSON documents at the moment.

Cheers,
Dimitris
Re: "EMC - JSON" for JSON object [message #1781410 is a reply to message #1781273] Wed, 07 February 2018 00:58 Go to previous messageGo to next message
Amir Kanan is currently offline Amir KananFriend
Messages: 22
Registered: July 2017
Junior Member
Hi Dimitris,

Thanks.

I need to understand the big picture of EMC layer to complete the EMC - JSON. right?
I guess, It would be useful for me to look at EMC - HTML or EMC - CSV.
https://github.com/epsilonlabs/epsilonlabs/blob/master/ImprovedCSVHHR/org.eclipse.epsilon.emc.csv/src/org/eclipse/epsilon/emc/csv/CsvModel.java
https://github.com/epsilonlabs/emc-html/blob/master/org.eclipse.epsilon.emc.html/src/org/eclipse/epsilon/emc/html/HtmlModel.java

Any suggestion?

Regards,
Amir
Re: "EMC - JSON" for JSON object [message #1781450 is a reply to message #1781410] Wed, 07 February 2018 12:15 Go to previous message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 195
Registered: October 2009
Location: UK
Senior Member

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
Epsilon Committer
Research Assistant
University Of York
Previous Topic:Create new element from a type using variable by EOL
Next Topic:Serializing back parsed EOL code
Goto Forum:
  


Current Time: Sat May 26 13:45:20 GMT 2018

Powered by FUDForum. Page generated in 0.02415 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top