The insertJson method inserts metadata from a JSON string, LuaJsonObject, or LuaJsonArray, into a document.
insertJson ( json [, fieldName] )
| Argument | Description |
|---|---|
json
|
(string or LuaJsonArray or LuaJsonObject) The JSON to insert into the document. |
fieldName
|
(string) The name of the metadata field to add the JSON to. This field is created if it does not exist. If you do not specify a field the JSON is added at the root of the document. |
The following example Lua script uses the insertJson method to add metadata to a document:
function handler(document)
local jsonString = [[
{"email":"example@domain.com",
"name":"A N Example",
"address":
{"address1":"New street",
"city":"Cambridge",
"country":"Great Britain"},
"id":15}
]]
document:insertJson( jsonString , "MyField")
return true
end
When written to an IDX file, the resulting document looks like this:
#DREREFERENCE c:\test.html #DREFIELD DREFILENAME="c:\test.html" ... #DREFIELD MyField/address/address1="New street" #DREFIELD MyField/address/city="Cambridge" #DREFIELD MyField/address/country="Great Britain" #DREFIELD MyField/email="example@domain.com" #DREFIELD MyField/id="15" #DREFIELD MyField/name="A N Example" #DRECONTENT Some content #DREENDDOC_FT_HTML5_bannerTitle.htm