Not sure if you guys have already coded up the JS bits of this but I'd really suggest leaving all this mangling to the JS app side of things. The idea of REST is to expose resources with data, this goes into application / implementation details too quickly.