Properly serialize scopes into json/xml