You shouldn't be using the JSON input for scripts. The best way to do it is by using the scripted fields option already available in Kibana. You get a detailed guide in that page and a way to test everything based on your data.