fileInpuFormat of type json

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

fileInpuFormat of type json

david
Hello,

Does the Flink Scala api have a method for reading json files? If not, are there any examples on how this is accomplished?

Thanks

-daviD
Reply | Threaded
Open this post in threaded view
|

Re: fileInpuFormat of type json

Fabian Hueske-2
Hi,

there are no built-in methods to read JSON.
How this can be done depends on the formatting of the JSON.
If you have a collection of JSON objects which are separated by newline (and there are no other newlines) you can read the file with env.readTextFile().
This will give you one String per line which can be parsed in a subsequent RichMapFunction. If you do that, you should make sure that the parser is initialized once (in open()) and not for every call of map().

Best, Fabian

2016-11-17 20:59 GMT+01:00 daviD <[hidden email]>:
Hello,

Does the Flink Scala api have a method for reading json files? If not, are there any examples on how this is accomplished?

Thanks

-daviD