@ScalarFunction
    @SqlType(StandardTypes.BOOLEAN)
    public static boolean isJsonScalar(@SqlType(StandardTypes.JSON) Slice json)
    {
        try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
            JsonToken nextToken = parser.nextToken();
            if (nextToken == null) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: " + truncateIfNecessaryForErrorMessage(json));
            }

            if (nextToken == START_ARRAY || nextToken == START_OBJECT) {
                parser.skipChildren();
                if (parser.nextToken() != null) {
                    // extra trailing token after json array/object
                    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: " + truncateIfNecessaryForErrorMessage(json));
                }
                return false;
            }

            if (parser.nextToken() != null) {
                // extra trailing token after json scalar
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: " + truncateIfNecessaryForErrorMessage(json));
            }
            return true;
        }
        catch (IOException e) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: " + truncateIfNecessaryForErrorMessage(json));
        }
    }
@Test
    public void testIsJsonScalar()
    {
        assertFunction("IS_JSON_SCALAR(null)", BOOLEAN, null);

        assertFunction("IS_JSON_SCALAR(JSON 'null')", BOOLEAN, true);
        assertFunction("IS_JSON_SCALAR(JSON 'true')", BOOLEAN, true);
        assertFunction("IS_JSON_SCALAR(JSON '1')", BOOLEAN, true);
        assertFunction("IS_JSON_SCALAR(JSON '\"str\"')", BOOLEAN, true);
        assertFunction("IS_JSON_SCALAR('null')", BOOLEAN, true);
        assertFunction("IS_JSON_SCALAR('true')", BOOLEAN, true);
        assertFunction("IS_JSON_SCALAR('1')", BOOLEAN, true);
        assertFunction("IS_JSON_SCALAR('\"str\"')", BOOLEAN, true);

        assertFunction("IS_JSON_SCALAR(JSON '[1, 2, 3]')", BOOLEAN, false);
        assertFunction("IS_JSON_SCALAR(JSON '{\"a\": 1, \"b\": 2}')", BOOLEAN, false);
        assertFunction("IS_JSON_SCALAR('[1, 2, 3]')", BOOLEAN, false);
        assertFunction("IS_JSON_SCALAR('{\"a\": 1, \"b\": 2}')", BOOLEAN, false);

        assertInvalidFunction("IS_JSON_SCALAR('')", INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: ");
        assertInvalidFunction("IS_JSON_SCALAR('[1')", INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: [1");
        assertInvalidFunction("IS_JSON_SCALAR('1 trailing')", INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: 1 trailing");
        assertInvalidFunction("IS_JSON_SCALAR('[1, 2] trailing')", INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: [1, 2] trailing");
    }