Hello
> Why i get an error if sends text but not error if send digits ?
Because text '123' is valid JSON. text 'text' - not valid. text '"text"' is valid JSON string.
Your example could be reduced to
> select cast(json_build_object('name','name')->>'name' as jsonb);
That means
> select cast('name'::text as jsonb);
Probably you wanted ->'name', not ->>'name'. JSON(b) operator -> will return json/jsonb type.
regards, Sergei