CC-5450 : Refactor Media Management

using recursion to build nested json responses.