Rename file based on extension

I am faced with the dillema of renaming 2 files that are in a folder based on extension. In a folder I have 2 filenames:

Yellow.jpg
Black.json

Is there a way to rename via AppleScript the .jpg file to have the same name as .json file? So the end result would be

Black.jpg
Black.json

Any help appreciated.

Thank you

something like this

tell application "Finder"
	set _F to choose folder
	set name of files of _F whose name is "Yellow.jpg" to "Black.jpg"
end tell

Or maybe:

set theFolder to (choose folder)

tell application "System Events"
	set jsonName to name of first file of theFolder whose name extension is "json"
	set newJPGName to text 1 thru -5 of jsonName & "jpg"
	set name of first file of theFolder whose name extension is "jpg" to newJPGName
end tell

A thing of beauty. Simple and efficient. Is there a way to apply the same script to a number of folders in the directory rather than selecting them one by one?

Thank you

This version handles every subfolder in a folder selected by the user:

set topFolder to (choose folder with prompt "Select the folder containing the folders you wish to process …")

tell application "System Events"
	set theSubfolders to topFolder's folders
	repeat with thisSubfolder in theSubfolders
		set jsonName to (name of first file of thisSubfolder whose name extension is "json")
		set newJPGName to text 1 thru -5 of jsonName & "jpg"
		set (name of first file of thisSubfolder whose name extension is "jpg") to newJPGName
	end repeat
end tell

This one allows the user to select several folders in the initial dialog:

set theFolders to (choose folder with prompt "Select the folder(s) you wish to process …" with multiple selections allowed)

tell application "System Events"
	repeat with thisFolder in theFolders
		set jsonName to (name of first file of thisFolder whose name extension is "json")
		set newJPGName to text 1 thru -5 of jsonName & "jpg"
		set (name of first file of thisFolder whose name extension is "jpg") to newJPGName
	end repeat
end tell

Neither script contains any error checks to make sure the folders contain both of the required files.

Works like a dream Mr.Garvey. Many thanks!!!