YouTube Connector 24.2

# insertJson

The `insertJson` method inserts metadata from a JSON string, LuaJsonObject, or LuaJsonArray, into a document.

## Syntax

    insertJson ( json [, fieldName] )

## Arguments

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.

## Example

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

Copyright 2024 Open Text
Version 24.2 | Last updated March 2024

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to MFI-swpdl.idoldocsfeedback@opentext.com.

We appreciate your feedback!

Product: IDOL YouTube Connector 24.2

Topic Title: insertJson