Factor out common JSON building pieces for item and collection.