Cannot Parse JSON Object: “[$http:baddata] Data Must be a Valid JSON Object” [duplicate]

Here is the outptut that I have and trying to get jobStatus inside jobStatus object. its throwing me cannot parse json object

var x = 
    { "jobStatus": 
      { "jobStatus"   : "COMPLETED"
      , "jobType"     : "xyz"
      , "scheduleType": "Immediate"
      , "startTime"   : "Oct 10, 2019 2:20:45 AM"
      , "endTime"     : "Oct 10, 2019 2:20:48 AM"
      , "Time"        : "Oct 10, 2019 2:20:40 AM"
      , "phase"       : "null"
      , "submittedBy" : "random"
      } 
    } 

code I’m using

Error :

[$http:baddata] Data must be a valid JSON object. Received: “COMPLETED”. Parse error: “{}” https://errors.angularjs.org/1.7.8/$http/baddata?p0=COMPLETED&p1=%7B%7D“`

var y = JSON.parse(x);
var status = y.jobStatus;
var y = JSON.parse(status);
var z = y.jobStatus;
Console.log(z)

This Post Has One Comment

  1. No Fault

    JSON or javascript object you don’t need to parse anything

    var x =
    { “jobStatus”:
    { “jobStatus” : “COMPLETED”
    , “jobType” : “xyz”
    , “scheduleType”: “Immediate”
    , “startTime” : “Oct 10, 2019 2:20:45 AM”
    , “endTime” : “Oct 10, 2019 2:20:48 AM”
    , “Time” : “Oct 10, 2019 2:20:40 AM”
    , “phase” : “null”
    , “submittedBy” : “random”
    }
    }

    let y = x.jobStatus.scheduleType
    console.log( y )
    // or
    let z = x[‘jobStatus’][‘jobType’]
    console.log( z )

    /* ——- */
    var A =
    { jobStatus:
    { jobStatus : “COMPLETED”
    , jobType : “xyz”
    , scheduleType: “Immediate”
    , startTime : “Oct 10, 2019 2:20:45 AM”
    , endTime : “Oct 10, 2019 2:20:48 AM”
    , Time : “Oct 10, 2019 2:20:40 AM”
    , phase : “null”
    , submittedBy : “random”
    }
    }
    let B = A.jobStatus.jobType
    console.log( B )
    // or
    let C = A[‘jobStatus’][‘scheduleType’]
    console.log( C )

Leave a Reply