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 = [[
     "name":"A N Example",
       {"address1":"New street",
        "country":"Great Britain"},

  document:insertJson( jsonString , "MyField")
  return true

When written to an IDX file, the resulting document looks like this:

#DREREFERENCE c:\test.html
#DREFIELD MyField/address/address1="New street"
#DREFIELD MyField/address/city="Cambridge"
#DREFIELD MyField/address/country="Great Britain"
#DREFIELD MyField/email=""
#DREFIELD MyField/id="15"
#DREFIELD MyField/name="A N Example"
Some content