Open topic with navigation

# lookupByPath

The `lookupByPath` method returns the value at the specified path in the JSON array.

NOTE:

This method does not make a copy of the value, so modifying the returned value affects the original object.

## Syntax

    lookupByPath( path )

## Arguments

Argument | Description
--- | ---
`path` | (string) The path of the value to return. Construct the path from array indexes and object attribute names, and use a slash (`/`) as the separator. If an object attribute name includes a slash, then escape the slash with a backslash, for example `"one\\/two"`. Notice that you must also escape a backslash with another backslash.

## Returns

(LuaJsonValue) Returns the value that exists at the specified path, or `nil` if the specified path does not exist.

## Example

    local myJsonObject = LuaJsonObject:new()
    myJsonObject:assign( {
            attr1=LuaJsonObject:new( { n=42, x=5 } ),
            attr2=LuaJsonArray:new( 1, 2, "three" ),
        } )

    local myJsonValue = LuaJsonValue:new( myJsonObject )

    print ( myJsonValue:lookupByPath("attr2/2"):value() )
    -- three (LuaJsonArrays are zero-indexed)

    -- Modifying the returned value changes the original object
    local lookup = myJsonValue:lookupByPath("attr1"):object()
    lookup:assign("y",3)
    print (myJsonValue:string())
    -- {"attr1":{"n":42,"x":5,"y":3},"attr2":[1,2,"three"]}

## See Also

- lookup

© 2017 Hewlett Packard Enterprise Development LP | Send documentation feedback to HPE Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to AutonomyTPFeedback@hpe.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_HP_HTML5_bannerTitle.htm