2 ms·
I have a shell script (technically PHP) that uses the clipboard to retrieve json, parses it and converts it into a correctly formatted php array then puts it ba
by noir_lord 5y ago
I have a shell script (technically PHP) that uses the clipboard to retrieve json, parses it and converts it into a correctly formatted php array then puts it back on the clipboard.
Fantastic for writing unit tests where you want to quickly freeze API responses and such.
There is more it could do but it's hands down the best RoI in terms of dev time I've had in a while.
- theFak 5y agoHow do you parse the text?
- noir_lord 5y agoReally simply, I grab the json from the copy buffer, use `json_decode` then `var_export` and then use some horrible regex stuff to reformat that into a modern short array syntax. So it looks like `json_to_array.sh --assign --clip` (if no clip just echoes the resulting PHP to stdout) https://kopy.io/aLpar https://kopy.io/aLpar (its not good code, it's an itch scratcher) - only works on Linux (it's all I use but would be trivial to make it work on a Mac I think). PHP makes a really good shell scripting language since it's a full blown language with a massive API and can 'talk' to the shell quite simply.