# 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 2020 Micro Focus or one of its affiliates | Send documentation feedback Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a mail client, and then send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm