in my sample, it should be like P.id = P1.id and P1.id =  P2.id.

It would work like that too.

Also, you self join on the identical fields "ID", so I guess the engine could infer p1.id = p2.id by "P.id  = P1.id and P.id = P2.id" , this would interfere my intention.

Please consider posting:

  • sample classes
  • sample data
  • description of data you want to get
  • what data you want to get
  • query

Additional JSON functionality, such as JSON (de)serialization for arbitrary classes was at one point available but currently under review. It may appear in one of future versions. I've posted a workaround.

You can also check RESTForms - REST API  for your persistent classes, it does support JSON (de)serialization. Another article about RESTForms.