0

I am trying to convert mentioned part of the JSON response from forecast api to POJO using http://www.jsonschema2pojo.org/. When I try to convert this to pojo the error says

There's a problem: Unexpected character ('l' (code 108)): was expecting double-quote to start field name (line 2, column 2)

Now I see that I need double quotes on each and every key param of json response. So I manually put double quotes and then I get the pojo class. SO my question is do I have to do it everytime and apply double quotes to every single keys ? Any other trick is there which I am missing ?

 {
  latitude: 45.4925827,
  longitude: -73.57789,
  timezone: "America/Montreal",
  offset: -4,
  currently: {
  time: 1496155473,
  summary: "Clear",
  icon: "clear-day",
  nearestStormDistance: 12,
  nearestStormBearing: 155,
  precipIntensity: 0,
  precipProbability: 0,
  temperature: 63.32,
  apparentTemperature: 63.32,
  dewPoint: 57.94,
  humidity: 0.83,
  windSpeed: 9.87,
  windBearing: 152,
  visibility: 10,
  cloudCover: 0.14,
  pressure: 1015.05,
  ozone: 346.1
  }
 }
Aalap Patel
  • 2,058
  • 2
  • 17
  • 31
  • That service wants the JSON property names to be enclosed in double quotes (`"`) like the JSON grammar says. Say, something like: `{"latitude": ...`. – Lyubomyr Shaydariv May 30 '17 at 16:11
  • You do not have to apply quotes to the params. Only when they are strings. bools can be `true`, `false`; floats can be straight up floats, etc. – jiveturkey May 30 '17 at 16:14
  • @LyubomyrShaydariv so as per the API response I am getting.. there are no double quotes in here so I will have to always manually put quotes and convert pojo class ? – Aalap Patel Jun 08 '17 at 21:17
  • @AalapPatel Either manually or by writing a tool. I would go with Gson or Jackson: they both can read such JSON documents (JSON requires quote signs in property names in standard!), and can emit valid JSON documents. So, for the latter, you just read your JSON document you have posted in the question, normalize it by writing to somewhere else, and then give the normalized JSON document to that service. Maybe there are even more simple ways, but I'm not aware of them. :) – Lyubomyr Shaydariv Jun 09 '17 at 11:49

0 Answers0