improved json generation