First you want to handle the JSON value: {"row0":{"field42":"120","field41":""}}
$field_value = json_decode('{"row0":{"field42":"120","field41":""}}');
$article_id = $field_value->row0->field42; // expected == 120
Thus, for you for getting the field value, it is going to be:
$field_value = json_decode($this->item->jcfields[40]->rawvalue);
$article_id = $field_value->row0->field42; // expected == 120
As you have the article ID then you can get the category ID and in few different ways you can build a route/URI:
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\RouteHelper;
// converting the json value
$field_value = json_decode($this->item->jcfields[40]->rawvalue);
$article_id = $field_value->row0->field42;
$app = Factory::getApplication();
$factory = $app->bootComponent('com_content')->getMVCFactory();
$table = $factory->createTable('Article', 'Table');
$table->load($article_id);
$item_catid = $table->catid;
$rhelper = new RouteHelper;
$myroute = $rhelper->getRoute($article_id, 'com_content.article', '', $language = ‘fr’, $catid = $item_catid);
This will create a value like:
'index.php?option=com_content&view=article&id=120&catid=12&lang=fr&Itemid=118'
Now, here comes the bad news: 'Itemid'
would be a menu ID and the problem with that is that you cannot query that based on article ID or category ID since many menu items can point to an article or category item, so the router is creating always the menu Itemid where the route was requested/created.
Thus, either you hardcode a menu ID in the URI or just leave that out from the URI.
So better if you create it half manually (without using the RouteHelper) with continuing the code from above:
$Uri = new Joomla\CMS\Uri\Uri;
$full_link = $Uri::base() . "index.php?option=com_content&view=article&id=" . $article_id . "&catid=" . $item_catid . "&lang=fr";
echo $full_link;
Everything is possible of course, but because of the basic concept of menu items in relations with category and article items, with the many-to-one relation, I do not see the easy way of querying menu items and choosing the right one from the many possible to create the right menu 'Itemid'
always for this URI. But maybe if you run on this question more you will find one solution on this part of the question too. I do not see that it worth the time though. I would approch this part of the question from another angle...