4

I'm looking for a language that would be suitable for describing tree-like application data migration.

We have an application that keeps it's data as a tree of "objects". If you try to express it as JSON, you can get something like that:

{
    "ROOT_OBJECT": {
        "@parameter1": 42,
        "@parameter2": "asdf",

        "CHILD_OBJECT": {
            "@parameter1": {
                "@subparameter1": 1
            },
            "@parameter2": [ "one", "two" ],

            "GRANDCHILD_OBJECT": {
                "@parameter1": 42
            }
        }
    }
}

The structure of the data evolves over time. The new application version might want to add some new parameters, remove some old ones, move parameters from one object to another, merge or split objects etc.

Such data migration can be written in an imperative language like Java or JavaScript (and it's more or less the way it is done now), but our intention is to move to a declarative one.

Currently we're developing an implementation that uses XSLT: it converts the tree to a DOM tree, applies an XSL transformation, then converts the result back to the original tree format.

I wonder whether there is an alternative way of doing such data transformation. Ideally the candidate language already has an implementation in Java and JavaScript, or at least in JavaScript.

tsayen
  • 2,875
  • 3
  • 18
  • 21
  • 1
    It appears XSLT is declarative and is well-suited for XML to XML tree manipulation and has implementations in Java. Its latest version 3.0 based on the array and map support in the underlying XSLT/XQuery/XPath data model and the various conversions between that model and JSON (https://www.w3.org/TR/xslt-30/#json) even allows you to work with JSON input or output if that is part of the task. So I wonder why XSLT, if you already know it and use it, is not the right tool and you look for other options? – Martin Honnen Oct 11 '16 at 10:57
  • Yes, XSLT looks like a suitable tool, I agree. The problem is, it has a "bad reputation", like many XML-related technologies nowadays. XSLT sounds boring and complicated and outdated to a lot of people. While I find it useful (I like XPath most, to be specific), it's hard to convince other people (especially those who had extensive experience with XML) to use it. It's usually like "Oh no, not XML again!". On the other hand, it looks a bit weird to me that there is apparently no general-purpose tree transformation language, so I wonder if I'm missing something. – tsayen Oct 11 '16 at 12:08
  • Maybe I missed it, but where do you need such transformations to be executed? On the server side or on some client(s)? – YSharp Oct 11 '16 at 17:51
  • Actually both :) Server side is Java, and client is JavaScript. Client-side JavaScript alone would be OK too, as we theoretically can run JS in Nashorn – tsayen Oct 11 '16 at 19:23
  • 2
    @tsayen : then you may want to have a look at this Q&A, there: http://stackoverflow.com/questions/1618038/xslt-equivalent-for-json – YSharp Oct 11 '16 at 19:58
  • @YSharp I saw this question already. Some of those solutions look nice, but they mostly require writing transformations in JavaScript (correct me if I'm wrong). JOLT transformations might be a solution, but It's Java only – tsayen Oct 12 '16 at 11:51

1 Answers1

0

TreeOps visual tool (https://github.com/treeops/treeops) transforms trees(JSON/XML/CSV) and generates Java code, however JavaScript is not supported yet. If Java is available on backend you can run it there.

TreeOps defines set of data tree transformations to facilitate typical data manipulations:

  1. filtering and deleting irrelevant data
  2. renaming and moving nodes along the tree
  3. flattening and de-flattening to convert between tree and tabular formats
  4. change nodes using regular expressions under selected nodes
  5. Transformations can be saved and re-applied again later. TreeOps can effortlessly generate Java classes that will read and represent transformed data as simple POJOs(plain old java objects).
asapozh
  • 1
  • 2