refactor writing of json elements for entities and relations
add macros where useful