Clean way of using ob_start() and ob_end_clean() in wordpress

WordPress has a whole set of useful functions to handle. It’s called wp_send_json(). You have success and error functions too.

ob_start(), ob_get_clean() would be useful in case you want to include some views (~ MVC) in your shortcode, e.g in your shortcode handler. I don’t see here why you would use them to pass data from PHP to js.

Otherwise I would use them in the shortcode handler, no use to put them in theme.