Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I parse this or convert this into JSON?

{
  name: 'com.riotgames.platform.summoner.PublicSummoner',
  keys: [ 'internalName', 'dataVersion', 'acctId', 'name', 'profileIconId', 'revisionDate', 'revisionId', 'summonerLevel', 'summonerId', 'futureData' ],
  object: {
    internalName: 'mrquackers',
    dataVersion: 0,
    acctId: { value: 34117327 },
    name: 'MrQuackers',
    profileIconId: 502,
    revisionDate: Tue, 30 Oct 2012 19:38:32 GMT,
    revisionId: { value: 0 },
    summonerLevel: { value: 30 },
    summonerId: { value: 20933307 },
    futureData: null
  },
  encoding: 0
}

(newlines and indentation added by editor; not part of the response)

It's a response from an RTMP packet and I'm not sure how I would go about parsing it. Is there a library in php or a way I can convert this into something easily parsable like json?

like image 591
user1684485 Avatar asked Nov 12 '22 18:11

user1684485


1 Answers

No. It is not possible to automatically parse a response if you don't know the language it uses.

While the response looks like JSON, it isn't. It's not even close to JSON. You can't just quote the keys to make it valid JSON.

Except for the revisionDate, it seems to be valid Javascript, but who knows?

The parser needs to know every data type it might potentially encounter. There's no telling what could appear in the response. Unless you find the documentation for this format, you never know what you might encounter.

You could in theory be able to parse the language you think this response is. But

  1. you need to implement your own parser. That's not easy. At all.
  2. you cannot assume you know the responder language. This response is one value from being valid javascript.
  3. a poorly implemented parser will not even know it met something it doesn't understand. Instead of giving up, it will produce unexpected results
  4. if you modify your model of the language, if your parser isn't a full-blown parser, incorporating the change into the parser could easily lead to a complete rewrite of the parser.

Conclusion:

You don't know the language the responder talks in. This means you cannot parse it. Find the documentation first, then talk about parsing.

like image 138
John Dvorak Avatar answered Nov 15 '22 08:11

John Dvorak