Hi Tom,
You didn't mention which version you are on. Doug is spot on for v15. For
v16+ you can take advantage of the native dot notation.

I sounds like you're on a newer version. When you write the code how
certain you are the object is properly constructed? Why do you say you
"have to use" OB Get? To enforce typing or because sometimes the value is
missing? Just wondering.

OB Get works on any object so you could call

$value:=OB
Get(myObject.data.object.billing_details.address;"postal_code";Is text)

and it will work because myObject.data.object.billing_details.address is an
object. But you could just as easily call

$value:=myObject.data.object.billing_details.address.posta_code


It's handy to break up objects like that if you are doing more than one
thing with them. I might do something like:

$adrs_obj:=myObject.data.object.billing_details.address

so that

$value:=$adrs_obj.posta_code


And this also makes it easier to update the address object:

$adrs_obj.posta_code:="new zip code"


Doing that also updates myObject and illustrates why objects and references
to them are so great. You can perhaps see that having a standard object for
all the addresses you use would allow you to write some methods for working
with them, or verifying them, that take an address object as the parameter
and modify the contents. Think looking up the lat/lon, correcting spelling,
verifying, etc.

My_address_verify($adrs_obj)


If you need to verify what's in the object you can use Null.

//  Is the address object defined?

if(myObject.data.object.billing_details.address # Null)  // yep

$value:=OB
Get(myObject.data.object.billing_details.address;"postal_code";Is text)
//  $value will be "" if postal_code is not there

end if


On Fri, Oct 25, 2019 at 1:58 PM Tom Benedict via 4D_Tech <
[email protected]> wrote:

> I’m new to objects. I have an object which holds a range of keys and
> values. Some of the values are objects. I figured I could just use the OB
> Get command with dot notation to reference a key in a nested object, but
> that doesn’t seem to be supported.
>
> Here’s my example:
>
> C_OBJECT(myObject)
>
> myObject :=
> "{
>   "id": "evt_1FXWZKGX5QBs0BzAQsOMqk3f",
>   "object": "event",
>   "created": 1572024442,
>   "data": {
>     "object": {
>       "object": "charge",
>       "amount": 4275,
>       "billing_details": {
>         "address": {
>           "city": "Burien",
>           "postal_code": "98166",
>           "state": "WA"
>         },
>         "name": "Willy Wonka",
>       },
>   "type": "charge.succeeded"
> }"
>
> If I want to get the value of:
>
> myObject.data.object.billing_details.address.postal_code
>
> I have to use:
>
> OB Get(OB Get(OB
> Get(myObject;"data");"object");”billing_details");”address");”postal_code”)
>
> rather than:
>
> OB Get(myObject;data.object.billing_details.address.postal_code)
>
> I see that Cannon created a dot notation component some years ago. Is that
> the only ‘easy’ way to do this or have I missed something?
>
> Thanks,
>
> Tom Benedict
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[email protected]
> **********************************************************************



-- 
Kirk Brooks
San Francisco, CA
=======================

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to