0

Is there a convenient nodeJS parsing library or function to reverse a string which was generated via toString() in PHP?

For example I generate the string in PHP:

O:8:"MyObject":1:{s:7:"*name";s:2:"JJ";}

(stolen from this example)

Now I'd like to reverse the operation in nodeJS to get a object back looking like:

{
  "name": "JJ"
}
sebastian
  • 813
  • 1
  • 7
  • 14
  • 1
    Dude, what?!1! If you want/need to transfer/convert data between node&php, i (personal) would chose json. – Marc Feb 08 '21 at 19:20
  • Yeah, I know. It is not that I like to be a masochist. I have a legacy wordpress database where data was persisted this way. Since I want to read and migrate the data I'm looking for a lib/function before writing my own parser. – sebastian Feb 08 '21 at 19:32
  • You can try to encode your data as json and see what comes out. But i hardly doubt that the example above is in any way a valid json string. But try it out, perhaps [json_encode](https://www.php.net/manual/en/function.json-encode.php) filter the "crap" for you out. Then you are ready to go/use the json string in node. – Marc Feb 08 '21 at 19:35

0 Answers0