Skip to main content
Inspiring
June 14, 2025
Answered

Lost extended information in custom fields - need to reinsert the data

  • June 14, 2025
  • 1 reply
  • 317 views

Long story, but I have lost about 5 years of extra information in custom fields, also backup. Luckely all this information is saved into a .json file with the images.
So for restoring them I was thinking to create a 'simple' lua script with a dialog for inserting this information back into lightroom.

 

My steps:

- Select the images where the information of the json file should be applied

- select the jason file

 

code not 100% correct but this should give  an idea of this will work

read the json file and put each value into a variable

ReturnContentFile = LrFileUtils.readFile(file) 
strTable = "{ " ..  ReturnContentFile .. " }"  
strTable = loadstring("return "..strTable)()
return strTable
-- must do the variable stuff
 
Put for each image the information into my custom fields
local catalog = LrApplication.activeCatalog()
for loop, photo in ipairs(photos) do
photo:readMetadata()
catalog:withPrivateWriteAccessDo(function(context)
photo:setPropertyForPlugin( _PLUGIN, 'MetaDataFile', "CFMetadata-"..CFMetadataFile)
photo:setPropertyForPlugin( _PLUGIN, 'AFFilmFormat', AFFilmFormat)
photo:setPropertyForPlugin( _PLUGIN, 'AFScanMethod', AFScanMethod)
photo:setPropertyForPlugin( _PLUGIN, 'AFScanEquipment', AFScanEquipment)
photo:setPropertyForPlugin( _PLUGIN, 'AFLightSource', AFLightSource)
photo:setPropertyForPlugin( _PLUGIN, 'AFDeveloppedAt', AFDeveloppedAt)
photo:setPropertyForPlugin( _PLUGIN, 'AFDevelopper', AFDevelopper)
photo:setPropertyForPlugin( _PLUGIN, 'AFDilution', AFDilution)
photo:setPropertyForPlugin( _PLUGIN, 'AFDevTime', AFDevTime)
photo:setPropertyForPlugin( _PLUGIN, 'AFDevNotes', AFDevNotes)
photo:setPropertyForPlugin( _PLUGIN, 'AFpushpull', AFpushpull)
photo:setPropertyForPlugin( _PLUGIN, 'AFFilmStock', StrFilmStock)
photo:setPropertyForPlugin( _PLUGIN, 'AFLightmeter', AFLightmeter)
photo:setPropertyForPlugin( _PLUGIN, 'ScanDevInfo', "ScanDevInfo-"..CFMetadataFile)
end ) 
end
 
Is this a good approach ?
Correct answer johnrellis

That approach should work. But I recommend doing very thorough error checking at each method call, since things can go wrong with LR scripts very quickly, in mysterious ways.

 

Also, you might out Friedl's JSON Encode/Decode module for reading the JSON files. It's very robust and used by many plugins (including mine):

https://regex.info/blog/lua/json 

 

I just verified that the LR/Transporter plugin isn't able to import values into plugin custom metadata fields. It can export them but not import, unfortunately. Otherwise, it might have been simpler to convert all the JSON files into a large CSV file to import.

1 reply

johnrellis
johnrellisCorrect answer
Brainiac
June 14, 2025

That approach should work. But I recommend doing very thorough error checking at each method call, since things can go wrong with LR scripts very quickly, in mysterious ways.

 

Also, you might out Friedl's JSON Encode/Decode module for reading the JSON files. It's very robust and used by many plugins (including mine):

https://regex.info/blog/lua/json 

 

I just verified that the LR/Transporter plugin isn't able to import values into plugin custom metadata fields. It can export them but not import, unfortunately. Otherwise, it might have been simpler to convert all the JSON files into a large CSV file to import.

Inspiring
June 14, 2025

Thank you John,
As always usesefull feedback.

It's not possible to create one large CSV file as each json file contains information for that specific directory.
The data is about the analog film used digitalisation and development.

Thank you for pointing out the Friedl"s JSON module, i'll look into it for future use. For now i'm going to use my own method to read a json file. A matter of getting my data back in as quickly as possible.