Search code examples
javajsoncommand-line-argumentsspacesargs

How to stop Java from separating JSON string passed as a command line argument into separate subunits of args[]


I want to pass this JSON String to a Java class through command line arguments.

{"body": "We should definitely meet up, man", "startDate": "2014-05-29 11:00:00", "endDate": "2014-05-29 12:00:00", "location": "Boca Raton", "subject": "This is the subject of our meeting."}

However, at every space, the String gets split up. So args[0] is

{"body":

args[1] is

"We

etc.

I want args[0] to just be

{"body": "We should definitely meet up, man", "startDate": "2014-05-29 11:00:00", "endDate": "2014-05-29 12:00:00", "location": "Boca Raton", "subject": "This is the subject of our meeting."}

I tried using double quotes, but since there are quotes in the JSON string it didn't work.

How can I do this? Thanks so much!


Solution

  • Here is a better solution:

    1. Stop passing json as a command line argument.
    2. Put the json in a file.
    3. Pass the name of the json file as a command line argument.
    4. Read the json file in your application.