json: export instructions

* flatten: reindex flatten result
* test: better test