title: unable to convert yaml string to json string using java
body: <p>I want to convert a <code>yaml</code> string to a <code>json</code> string by using "jyaml", kindly some one help me to resolve this</p>
  
  <p>YAML string :-</p>
  
  <pre><code>Korea:   www.gozoculture.com:     default: jhfjfjfj  www.5plus5.gov.mt:     default: jhfjfjfj  www.ces.gov.mt:     default: cesDefault    user5: chennal5  isp:     Tata DoCoMo: chennalisp1    Hathway: chennalIsp    Hong Kong: chennalisp2    Aircel: chennalIspaircel    Airtel: chennalIspAirtel  studiodefault: KoreaStudioDefault  www.wwe.com:     default: wweDefault    user2: chennal2    user1: chennal1  country:     FR: francecountryChennal    HK: HongkongCountryChennal    IN: IndaiChennal    DE: GermanyCountryChennal
  </code></pre>
  
  <p>my expected output:-</p>
  
  <pre><code>{
    "Singapoor": {
      "studiodefault": "chennal default singapoor site", 
      "www.gozoculture.com": {
        "default": "chennalDefault1", 
        "user1": "ch1,ch2,ch3"
      }, 
      "country": {
        "FR": "franceChennal", 
        "DE": "GermanyChennal", 
        "IN": "indiaChennal"
      }, 
      "www.justice.gov.mt": {
        "default": "justiceDefault"
      }, 
      "www.wwe.com": {
        "default": "wwechennalDefault", 
        "user2": "ch4,ch5,ch6"
      }, 
      "isp": {
        "Vodafone  Broadband": "vodafoneChennal2", 
        "Idea cellular": "ideaChennal", 
        "Airtel": "aritelChennal1"
      }, 
      "www.enemalta.com": {
        "default": "chennalDefault2", 
        "user3": "ch7,ch8,ch9"
      }
    }
  }
  </code></pre>
  
  <p>java code:-</p>
  
  <pre><code>private static String convertToJson(String yamlString) {
      Yaml yaml= new Yaml();
      Map&lt;String,Object&gt; map= (Map&lt;String, Object&gt;) yaml.load(yamlString);
  
      JSONObject jsonObject=new JSONObject(map);
      return jsonObject.toString();
  }
  </code></pre>
  
  <p>output I am getting :-</p>
  
  <pre><code>"Korea":   "www.gozoculture.com:     default: jhfjfjfj  www.5plus5.gov.mt:     default: jhfjfjfj  www.ces.gov.mt:     default: cesDefault    user5: chennal5  isp:     Tata DoCoMo: chennalisp1    Hathway: chennalIsp    Hong Kong: chennalisp2    Aircel: chennalIspaircel    Airtel: chennalIspAirtel  studiodefault: KoreaStudioDefault  www.wwe.com:     default: wweDefault    user2: chennal2    user1: chennal1  country:     FR: francecountryChennal    HK: HongkongCountryChennal    IN: IndaiChennal    DE: GermanyCountryChennal"
  </code></pre>
  
  <p>my alternative yaml input file:-</p>
  
  <pre><code>Singapoor: 
    www.gozoculture.com: 
      default: chennalDefault1
      user1: ch1,ch2,ch3
    isp: 
      Airtel: aritelChennal1
      Vodafone  Broadband: vodafoneChennal2
      Idea cellular: ideaChennal
    www.enemalta.com: 
      default: chennalDefault2
      user3: ch7,ch8,ch9
    www.justice.gov.mt: 
      default: justiceDefault
    studiodefault: chennal default singapoor site
    www.wwe.com: 
      default: wwechennalDefault
      user2: ch4,ch5,ch6
    country: 
      FR: franceChennal
      IN: indiaChennal
      DE: GermanyChennal
  </code></pre>
  
  <p>when I trying to upload single key with multiple values like "user2: ch4,ch5,ch6". for this case my code does not work. I am getting this exception
  :</p>
  
  <pre><code>Jun 18, 2015 5:29:23 PM com.sun.jersey.spi.container.ContainerResponse logException
  SEVERE: Mapped exception to response: 500 (Internal Server Error)
  javax.ws.rs.WebApplicationException: org.ho.yaml.exception.YamlException: Error near line 4: Unterminated inline value
  </code></pre>