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

args, command-line-arguments, java, json, spaces

Solution

Here is a better solution:

- Stop passing json as a command line argument.

- Put the json in a file.

- Pass the name of the json file as a command line argument.

- Read the json file in your application.

Problem

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!

Original source

Related problems