0
Legs: [{
  'dollar': {
    xmlns: 'HitchHiker.FlightAPI.FareRequestStructs'
  },
  FareRequestLeg: [{
    ArrivalSearchRadius: ['0'],
    ArrivalTime: [{
      'dollar': {
        'xsi:nil': 'true'
      }
    }],
    Class: ['Economy'],
    Connections: [''],
    DepartureDate: ['2020-10-22T00:00:00'],
    DepartureSearchRadius: ['0'],
    DepartureTime: [{
      'dollar': {
        'xsi:nil': 'true'
      }
    }],
  }]
}]

I have some thing like that. I had a xml file. I use Xml2js for parsing , here i got a this string I want Object from of this.

clear view : https://pastebin.com/ZvPAbdgw

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • 1
    This isn't valid JSON. The keys and strings need to be wrapped in double quotes `"`. I suggest you fix the format so the JSON is valid and you can use JSON.parse on it. Also, I assume there is more of this that you're not showing, however, if this is the entirety of the file, that `Legs:` is not a valid start, either. – VLAZ Oct 17 '20 at 09:35
  • how can i fix this format ? can you help me? – Nazrul Islam Oct 17 '20 at 10:07

1 Answers1

0

Use something like https://jsonlint.com/ to check your json format, I fixed few lines for you

{
    "Legs": [{
        "dollar": {
            "xmlns": "HitchHiker.FlightAPI.FareRequestStructs"
        }
    }]
}

then you could assign it to a variable.

const json = {
    "Legs": [{
        "dollar": {
            "xmlns": "HitchHiker.FlightAPI.FareRequestStructs"
        }
    }]
}

If the format returned is string you would need to do https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

const jsonObj = JSON.parse("your json string")
Frank Dax
  • 108
  • 7