# parse_json

The `parse_json` function parses a string of JSON and returns a JSON value.

## Syntax

    parse_json( json )

## Arguments

Argument | Description
--- | ---
`json` | (string) The input string to parse.

## Returns

(LuaJsonValue). A LuaJsonValue containing the JSON data.

## Example

    local fh = io.open("example_json.json", "r")
    local file_content = fh:read("*all")
    fh:close()

    local myJsonValue = parse_json(file_content)

    if myJsonValue:is_object() then
      document:insertJson( myJsonValue:object() , "MyJsonField" )
    elseif myJsonValue:is_array() then
      document:insertJson( myJsonValue:array() , "MyJsonField" )
    end

If the file `example_json.json` contained the following JSON object:

    {
      "product": "IDOL",
      "component": "CFS",
      "version": { "major": 11, "minor": 3 },
      "ports": [
        { "type": "ACI", "number": 7000 },
        { "type": "Service", "number": 17000 }
      ]
    }

The resulting document might look like this:

    <document>
       <reference>ref1</reference>
       <xmlmetadata>
          <MyJsonField>
            <component>CFS</component>
            <ports>
              <number>7000</number>
              <type>ACI</type>
            </ports>
            <ports>
              <number>17000</number>
              <type>Service</type>
            </ports>
            <product>IDOL</product>
            <version>
              <major>11</major>
              <minor>3</minor>
            </version>
          </MyJsonField>
       </xmlmetadata>
    </document>

## See Also

If you know that the input data is a JSON object, you can also use the function parse_json_object. If you know that the input data is a JSON array, you can also use the function parse_json_array.

© Copyright 2019 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