added common functions for writing json data segments