The Wayback Machine - https://web.archive.org/web/20210123045913/https://github.com/valathsu/PythonJavaRepository
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

README.md

PythonJavaRepository

Code to achieve json normalization in Java via python

What this code does?

  • This is a sample code to perform json normalization in java with the help of python.

Why I have written this code?

  • We had a requirement where input json needs to be normalized inorder to be written to db.
  • No utility for this requirement is available in Java out of box and we end up writting very messy custom code.
  • Found that this utility is readily availble in python via pandas module.So no need of 're-inventing the wheel' again. Hence written a java wrapper over python to achieve it.

What is 'normalization' by the way and what do pandas do?

Sound coool, well how to run this?

  • Please find steps below to run the same.

  • Please refer http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.io.json.json_normalize.html to model your input json data.

  • I have used the same example explanied in the above link to run the code.

  • First and formost, we you are a java developer, its time to show some love to python2. Please install python2 and pandas module to run this program.

  • Following are the arguments and orders to be passed to this java program : arg[0] = path to python executable arg[1] = path to python script file arg[2] = input json file arg[3] = record path arg[4] = meta

    Last three arguments needs to be formatted a bit, inorder to make it ready for python to execute it as command line arguments. For example :

    In order to run this program please give the following String as arguments to this java program:

    "--path to python executable OR env_variable name--"

    "--path to python file to be executed--"

    ""[{""state"":""Florida"",""shortname"":""FL"",""info"":{""governor"":""RickScott""},""counties"":[{""name"":""Dade"",""population"":12345},{""name"":""Broward"",""population"":40000},{""name"":""PalmBeach"",""population"":60000}]},{""state"":""Ohio"",""shortname"":""OH"",""info"":{""governor"":""JohnKasich""},""counties"":[{""name"":""Summit"",""population"":1234},{""name"":""Cuyahoga"",""population"":1337}]}]""

    ""counties""

    ""[""state"", ""shortname"",[""info"", ""governor""]]""

Where is the python script by the way?

  • You may find a simple py script file named "normalization.py" in source code.

So whats next?

  • Please check this if it fits into your requirements and let me know for issues or bugs.

Happy coding and have a nice day.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.