Repository: diesel-rs/diesel
File: diesel/src/pg/expression/functions.rs (Rust)

Code before:
    ///     "f4",
    ///     "f6"
    /// ))
    /// .get_result::<Option<String>>(connection)?;
    ///
    /// assert_eq!(expected, result);
    ///
    /// let result = diesel::select(json_extract_path_text_1::<Nullable<Json>, Text, _, _>(None::<serde_json::Value>, "f4"))
    /// .get_result::<Option<String>>(connection)?;
    ///
    /// assert_eq!(None::<String>, result);
    ///
    /// let result = diesel::select(json_extract_path_text_2::<Json, Nullable<Text>, Text, _, _, _>(json!({"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}), None::<String>, "f6"))
    /// .get_result::<Option<String>>(connection)?;
    ///
    /// assert_eq!(None::<String>, result);
    ///
    /// #     Ok(())
    /// # }
    /// ```
    #[cfg(feature = "postgres_backend")]
    #[sql_name = "json_extract_path_text"]
    #[variadic(last_arguments = 1, skip_zero_argument_variant = true)]
    fn json_extract_path_text<J: JsonOrNullableJson + SingleValue, T: SingleValue>(
        json: J,
        text: T,
    ) -> Nullable<Text>;

    /// Extracts JSON sub-object at the specified path as text. (This is functionally equivalent to the #>> operator.)
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     #[cfg(feature = "serde_json")]
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # #[cfg(feature = "serde_json")]
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::{jsonb_extract_path_text_1, jsonb_extract_path_text_2};
    /// #     use diesel::sql_types::{Jsonb, Nullable, Text};
    /// #     use serde_json::{json,Value};
    /// #     use diesel::dsl::sql;
    /// #     let connection = &mut establish_connection();
    ///
    /// let expected = Some(String::from("{\"f5\": 99, \"f6\": \"foo\"}"));
    /// let result = diesel::select(jsonb_extract_path_text_1::<Jsonb, Text, _, _>(
    ///     json!({"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}),

Review comment (refactor):
This needs to be 
```suggestion
    fn json_extract_path_text<J: JsonOrNullableJson + SingleValue, T: TextOrNullableText>(
        json: J,
        text: T,
```

as the second argument needs to be an expression of the type `Text`. Other expression types are not supported there.

(This applies to the jsonb variant as well)

Code after:
    ///     json!({"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}),
    ///     "f4",
    ///     "f6"
    /// ))
    /// .get_result::<Option<String>>(connection)?;
    ///
    /// assert_eq!(expected, result);
    ///
    /// let result = diesel::select(json_extract_path_text_1::<Nullable<Json>, Text, _, _>(None::<serde_json::Value>, "f4"))
    /// .get_result::<Option<String>>(connection)?;
    ///
    /// assert_eq!(None::<String>, result);
    ///
    /// let result = diesel::select(json_extract_path_text_2::<Json, Nullable<Text>, Text, _, _, _>(json!({"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}), None::<String>, "f6"))
    /// .get_result::<Option<String>>(connection)?;
    ///
    /// assert_eq!(None::<String>, result);
    ///
    /// #     Ok(())
    /// # }
    /// ```
    #[cfg(feature = "postgres_backend")]
    #[sql_name = "json_extract_path_text"]
    #[variadic(last_arguments = 1, skip_zero_argument_variant = true)]
    fn json_extract_path_text<
        J: JsonOrNullableJson + SingleValue,
        T: SingleValue + TextOrNullableText,
    >(
        json: J,
        text: T,
    ) -> Nullable<Text>;

    /// Extracts JSON sub-object at the specified path as text. (This is functionally equivalent to the #>> operator.)
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     #[cfg(feature = "serde_json")]
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # #[cfg(feature = "serde_json")]
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::{jsonb_extract_path_text_1, jsonb_extract_path_text_2};
    /// #     use diesel::sql_types::{Jsonb, Nullable, Text};
    /// #     use serde_json::{json,Value};
    /// #     use diesel::dsl::sql;
    /// #     let connection = &mut establish_connection();