0

I am getting exception while reading JSON response which is provided by HTTPBuilder in Groovy. please find the JSON string below. I am getting JSON response without quotes. I am using Groovy HTTPBuilder.

String x = {
  apenvironments = [], temptype = dflt, audit = {
      createdAt = 1438605399389,
        createdBy = xxxxxx testing
    }, basicInfo = {
      id = AU7zkFVftRWGykHHiM1R,
        name = MED_FREQ83282
    }, id = AU7zkFVftRWGykHHiM1R, name = MED_FREQ83282,
    policyElements = [{
      authenticationType = AUTH12, type = AUTH
    }, {
      aggType = COUNT, soft = false, targets = [{
        targetType = APPS, type = BasePolicyElementTarget
      }], type = numrclmt, value = 5, valueEqualsZero = false
    }, {
      aggType = COUNT, soft = false, targets = [{
        targetType = DEVICE, type = BasePolicyElementTarget
      }], type = numerratlimt, value = 3, valueEqualsZero = false
    }, {
      enabled = true, type = ANALYTICS
    }, {
      meteringPayloadType = REQUEST, metricField = PAYLOAD, type = PAYLOAD_METERING
    }, {
      field = PAYLOAD, load = {
        bandwidthUnit = KB, payloadType = REQUEST, type = payload, value = 26
      }, soft = false, type = Payload, valueEqualsZero = false
    }, {
      aggType = COUNT, soft = false, targets = [{
        targetType = USER, type = elementTarget
      }], type = ratelt, value = 4, valueEqualsZero = false
    }, {
      hitType = ALL, metricField = HITS, type = meter
    }, {
      frequencyUnit = MINUTE, hits = {
        hitType = ALL, hits = 3
      }, metricField = HITS, soft = false, type = freqratelt, valueEqualsZero = false
    }], templateName = tempv, type = plctem
};      


ObjectMapper mapper = new ObjectMapper();

try {
    JsonNode df=mapper.readValue(x,JsonNode.class);

...............

Exception: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('a' (code 97)): was expecting double-quote to start field name

Please help me on this.

Mouser
  • 13,132
  • 3
  • 28
  • 54
  • Welcome to Stack Overflow. When you were asking your question, there was a big orange **How to Format** box to the right of the text area with useful information in it. There was also an entire toolbar of formatting aids. And a **[?]** button giving formatting help. *And* a preview area located between the text area and the Post Your Question button (so that you'd have to scan past it to find the button) showing what your post would look like when posted. Please make use of them in future. You can use the "edit" link under your question to correct it. – T.J. Crowder Aug 03 '15 at 14:10
  • Looks like you need to encode this from a javascript object to a valid JSON string. But event the JavaScript source is flawed, since the values do not have quotes around them. Even in a JavaScript enviroment this will throw a bunch of errors. – Mouser Aug 03 '15 at 14:13
  • This shows you have JSON should look, and how to put it in an array http://www.json.com/json-example There are a number of JSON validators/linters which you can use to check your JSON before running your code – Mousey Aug 03 '15 at 16:57

0 Answers0