refactor XML attribute to JSON code to avoid duplication