NetTalk Central

Author Topic: json group in queue  (Read 889 times)

ntnewbies

  • Full Member
  • ***
  • Posts: 169
    • View Profile
    • Email
json group in queue
« on: December 11, 2023, 04:01:47 AM »
hi friends,
i have this json declaration

element                  Group,Name('element')
id                         STRING(255),Name('id')
object                     STRING(255),Name('object')
application_               String(250) ,Name('application| opt')
application_fee_percent    String(250) ,Name('application_fee_percent| opt')
automatic_tax              Group,Name('automatic_tax')
enabled                      Byte,Name('enabled | boolean')
                           End
billing_cycle_anchor       Real,Name('billing_cycle_anchor| opt')
billing_thresholds         String(250) ,Name('billing_thresholds')
cancel_at                  String(250) ,Name('cancel_at| opt')
cancel_at_period_end       Byte,Name('cancel_at_period_end| opt | boolean')
canceled_at                String(250) ,Name('canceled_at| opt')
cancellation_details       Group,Name('cancellation_details')
comment                      String(250) ,Name('comment')
feedback                     String(250) ,Name('feedback')
reason                       String(250) ,Name('reason')
                           End
collection_method          STRING(255),Name('collection_method| opt')
created                    Real,Name('created')
currency                   STRING(255),Name('currency')
current_period_end         Real,Name('current_period_end| opt')
current_period_start       Real,Name('current_period_start| opt')
customer                   STRING(255),Name('customer| opt')
days_until_due             String(250) ,Name('days_until_due| opt')
default_payment_method     String(250) ,Name('default_payment_method| opt')
default_source             String(250) ,Name('default_source| opt')
default_tax_rates          String(240) ,Dim(10),Name('default_tax_rates| opt')
description                String(250) ,Name('description| opt')
discount                   String(250) ,Name('discount| opt')
ended_at                   String(250) ,Name('ended_at| opt')
items                      Group,Name('items')
object                       STRING(255),Name('object')
data_                        &dataQueueType,Name('data | queue')
has_more                     Byte,Name('has_more | boolean')
total_count                  Real,Name('total_count')
url                          STRING(255),Name('url')
                           End
latest_invoice             STRING(255),Name('latest_invoice| opt')
livemode                   Byte,Name('livemode | boolean')
metadata                   Group,Name('metadata')
                           End
next_pending_invoice_item_invoice String(250) ,Name('next_pending_invoice_item_invoice| opt')
on_behalf_of               String(250) ,Name('on_behalf_of| opt')
pause_collection           String(250) ,Name('pause_collection| opt')
payment_settings           Group,Name('payment_settings')
payment_method_options       String(250) ,Name('payment_method_options')
payment_method_types         String(250) ,Name('payment_method_types')
save_default_payment_method  STRING(255),Name('save_default_payment_method')
                           End
pending_invoice_item_interval String(250) ,Name('pending_invoice_item_interval| opt')
pending_setup_intent       String(250) ,Name('pending_setup_intent| opt')
pending_update             String(250) ,Name('pending_update| opt')
quantity                   Real,Name('quantity')
schedule                   String(250) ,Name('schedule| opt')
start_date                 Real,Name('start_date| opt')
status                     STRING(255),Name('status| opt')
test_clock                 String(250) ,Name('test_clock| opt')
transfer_data              String(250) ,Name('transfer_data| opt')
trial_end                  String(250) ,Name('trial_end| opt')
trial_settings             Group,Name('trial_settings')
end_behavior                 Group,Name('end_behavior')
missing_payment_method         STRING(255),Name('missing_payment_method')
                             End
                           End
trial_start                String(250) ,Name('trial_start| opt')
                         End
dataQueueType             Queue,Type,Name('data')
id                         STRING(255),Name('id')
object                     STRING(255),Name('object')
billing_thresholds         String(250) ,Name('billing_thresholds')
created                    Real,Name('created')
metadata                   Group,Name('metadata')
                           End
plan                       Group,Name('plan')
id                           STRING(255),Name('id')
object                       STRING(255),Name('object')
active                       Byte,Name('active | boolean')
aggregate_usage              String(250) ,Name('aggregate_usage')
amount                       Real,Name('amount')
amount_decimal               STRING(255),Name('amount_decimal')
billing_scheme               STRING(255),Name('billing_scheme')
created                      Real,Name('created')
currency                     STRING(255),Name('currency')
interval                     STRING(255),Name('interval')
interval_count               Real,Name('interval_count')
livemode                     Byte,Name('livemode | boolean')
metadata                     Group,Name('metadata')
                             End
nickname                     String(250) ,Name('nickname')
product                      STRING(255),Name('product')
tiers_mode                   String(250) ,Name('tiers_mode')
transform_usage              String(250) ,Name('transform_usage')
trial_period_days            String(250) ,Name('trial_period_days')
usage_type                   STRING(255),Name('usage_type')
                           End
price                      Group,Name('price')
id                           STRING(255),Name('id')
object                       STRING(255),Name('object')
active                       Byte,Name('active | boolean')
billing_scheme               STRING(255),Name('billing_scheme')
created                      Real,Name('created')
currency                     STRING(255),Name('currency')
custom_unit_amount           String(250) ,Name('custom_unit_amount')
livemode                     Byte,Name('livemode | boolean')
lookup_key                   String(250) ,Name('lookup_key')
metadata                     Group,Name('metadata')
                             End
nickname                     String(250) ,Name('nickname')
product                      STRING(255),Name('product')
recurring                    Group,Name('recurring')
aggregate_usage                String(250) ,Name('aggregate_usage')
interval                       STRING(255),Name('interval')
interval_count                 Real,Name('interval_count')
trial_period_days              String(250) ,Name('trial_period_days')
usage_type                     STRING(255),Name('usage_type')
                             End
tax_behavior                 STRING(255),Name('tax_behavior')
tiers_mode                   String(250) ,Name('tiers_mode')
transform_quantity           String(250) ,Name('transform_quantity')
type                         STRING(255),Name('type')
unit_amount                  Real,Name('unit_amount')
unit_amount_decimal          STRING(255),Name('unit_amount_decimal')
                           End
quantity                   Real,Name('quantity')
subscription               STRING(255),Name('subscription')
tax_rates                  String(240) ,Dim(10),Name('tax_rates')
                         End


as you notice, there are several occurence of 'id'

i need to get the value of id after plan:

plan                       Group,Name('plan')
id                           STRING(255),Name('id')


i cant get it via json.GetValueByName
any suggestion please
thanks.

jason
c11
nt12.62
jf3

seanh

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Email
Re: json group in queue
« Reply #1 on: December 11, 2023, 02:58:08 PM »
If you load the entire json into that clarion structure I "think" you'd  refer to it as element.plan.id

ntnewbies

  • Full Member
  • ***
  • Posts: 169
    • View Profile
    • Email
Re: json group in queue
« Reply #2 on: December 11, 2023, 07:19:30 PM »
hi sean,
i did the following

  json.start()
  json.SetTagCase(jf:CaseAsIs)
  json.LoadString(st)

  PriceID = element.plan.id

But i get the error -> Field not found: PLAN

ntnewbies

  • Full Member
  • ***
  • Posts: 169
    • View Profile
    • Email
Re: json group in queue
« Reply #3 on: December 11, 2023, 09:36:01 PM »
hi
i have tried this but still no value returned

    element.items.data_ &= NEW dataQueueType
    PriceId = element.items.data_.plan.id

regards,
jason
c11
nt12.62
jf3

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11182
    • View Profile
Re: json group in queue
« Reply #4 on: December 11, 2023, 10:13:34 PM »
you could get a json object, which is unique. Then look inside that to get the id.

for example (not tested)

planjson  &jsonclass
id  string(10)
 
  planjson &= GetByName('plan')
  if not planjson &= null
    id = planjson.GetValueByName('id')
  end

Cheers
Bruce

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11182
    • View Profile
Re: json group in queue
« Reply #5 on: December 11, 2023, 10:15:44 PM »
i did the following

  json.start()
  json.SetTagCase(jf:CaseAsIs)
  json.LoadString(st)

that code will fail because you are not loading anything into element. You're loading the json tree, but you're not moving the json tree into the element group.

Cheers
Bruce

ntnewbies

  • Full Member
  • ***
  • Posts: 169
    • View Profile
    • Email
Re: json group in queue
« Reply #6 on: December 11, 2023, 11:09:25 PM »
hi bruce,
i capture the api, remove the header and save response values (which is in json) into a string theory (st)
and then i did the following

  json.start()
  json.SetTagCase(jf:CaseAsIs)
  json.LoadString(st)


   i could get non queue values such as element.id

  the word id is used several times in the returned json. so if i use getvaluebyname, most likely it will get the first one only,
  right?

  also, planjson &= GetByName('plan')   gives error  -> no matching prototype available.
but i have declared it in the local declaration as planjson  &jsonclass

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11182
    • View Profile
Re: json group in queue
« Reply #7 on: December 11, 2023, 11:42:01 PM »
>> i could get non queue values such as element.id

not with that code you can't.
The code you have there does not load the Element group.
You are just loading the tree from the string, not moving the tree to the element group.

>>   the word id is used several times in the returned json. so if i use getvaluebyname, most likely it will get the first one only, right?

sure, which is why you can narrow the scope to the parent node. But this is irrelevant if you move it into the group.

<<   also, planjson &= GetByName('plan')   gives error  -> no matching prototype available.

sure - that's why I said it was untested. Feel free to read the docs, or the INC file, to get the correct method name. You're looking for a pointer to a node in the tree.

Cheers
Bruce

ntnewbies

  • Full Member
  • ***
  • Posts: 169
    • View Profile
    • Email
Re: json group in queue
« Reply #8 on: December 12, 2023, 01:38:53 AM »
thanks bruce,
i overlooked something. so eager to solve it and didnt see a minor thing.

the tested working code should be:

  planjson &= json.GetByName('plan')

  if not planjson &= null
        planid = planjson.GetValueByName('id')       
  end