Writing a JSON file

119 views
Skip to first unread message

Dwayne

unread,
May 24, 2013, 7:14:38 AM5/24/13
to scrip...@googlegroups.com
Hi,

I'd like to read some sort of input (e.g. CSV) and write out a JSON representation. I'm thinking I would use the scripting feature to read in the data and populate a Javascript object and somehow write out the contents of that JavaScript object... is that the correct approach? Is there a better/suggested way? Any example would be great.

Thanks,
Dwayne

Ivan Kovalenko

unread,
May 24, 2013, 7:23:09 AM5/24/13
to scrip...@googlegroups.com
i guess, scriptella is perfectly suited for that, but of course you could use awk for that =)


2013/5/24 Dwayne <dwayne....@groupbyinc.com>

--
You received this message because you are subscribed to the Google Groups "Scriptella ETL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scriptella+...@googlegroups.com.
To post to this group, send email to scrip...@googlegroups.com.
Visit this group at http://groups.google.com/group/scriptella?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Fyodor Kupolov

unread,
May 29, 2013, 8:58:15 AM5/29/13
to scrip...@googlegroups.com
Hi,

There are multiple solutions for your problem. The easiest in terms of implementation(but probably not covering all possible usecases) would be to use a text driver for manually producing JSON output. Something like this:
<query connection-id="csv">
   <script connecton-id="text">
         { 
               id: "$id",
               name: "$name"
         }
    </script>
</query>
Please note that you might need escaping of outputted values,  ${name.replaceAll("fromRegex", "toRegEx")} or a dedicated utility method can be used for that purpose.

Another way of producing JSON output is to use Janino for producing an object from CSV properties and serialize it to String as JSON using some third-party library like Jackson. But it's more complex. 

Probably the most complex way, but also a very helpful for the community would be to create a driver for running queries(in JSON syntax) over JSON content in <query> elements and output a properly as escaped JSON in <script>. 
Reply all
Reply to author
Forward
0 new messages