make JSON generation smarter