YouTube Connector 12.11

# 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 2022 Micro Focus or one of its affiliates
Version 12.11 | Last updated February 2022

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 swpdl.idoldocsfeedback@microfocus.com.

We appreciate your feedback!

Product: IDOL YouTube Connector 12.11

Topic Title: parse_json