Hello,
Would anyone be able to offer some assistance to me parsing some JSON. I have been trying to do this for about a week now an can't seem to make any progress.
The JSON I am interested is the response from this URL:
https://1ml.com/channel?json=true
I would like to be able to parse out the following:
"channel_ID"
"fee_base_msat"
"fee_rate_milli_msat"
Any help with this would be most gratefully appreciated.
Regards
AW
Help with JSONPARSE
Moderators: JRL, Dorian (MJT support)
- Dorian (MJT support)
- Automation Wizard
- Posts: 1417
- Joined: Sun Nov 03, 2002 3:19 am
Re: Help with JSONPARSE
Here you go. This thread explains the reason for the problem.
The solution was to fix it with StringReplace, and then parse.
The solution was to fix it with StringReplace, and then parse.
Code: Select all
//https://1ml.com/channel?json=true
//"channel_id"
//"fee_base_msat"
//"fee_rate_milli_msat"
HTTPRequest>https://1ml.com/channel?json=true,,GET,,sJSON
stringreplace>sJSON,[,{"things":[,sJSON
stringreplace>sJSON,],]},sJSON
JSONParse>sJSON,$.things[*].channel_id,chanID
JSONParse>sJSON,$.things[*].node1_policy.fee_base_msat,feebase
JSONParse>sJSON,$.things[*].node1_policy.fee_rate_milli_msat,feerate
mdl>%chanID_count% results
//let's loop through the output
Let>k=0
Repeat>k
Let>k=k+1
Let>this_chanID=chanID_%k%
MessageModal>this_chanID
Let>this_feebase=feebase_%k%
MessageModal>this_feebase
Let>this_feerate=feerate_%k%
MessageModal>this_feerate
Until>k=chanID_count
Re: Help with JSONPARSE
alternative:
I note you have more than one feebase/feerate per channel so depends how you want to parse it out.
Eg feerate for node1_policy:
Code: Select all
HTTPRequest>https://1ml.com/channel?json=true,,GET,,sJSON
JSONParse>sJSON,$..channel_id,ChannelID
JSONParse>sJSON,$..fee_base_msat,feebase
JSONParse>sJSON,$..fee_rate_milli_msat,feerate
Eg feerate for node1_policy:
Code: Select all
JSONParse>sJSON,$..node1_policy.fee_rate_milli_msat,feerate
- Dorian (MJT support)
- Automation Wizard
- Posts: 1417
- Joined: Sun Nov 03, 2002 3:19 am
Re: Help with JSONPARSE
Just wanted to say thank you.hagchr wrote: ↑Tue May 31, 2022 5:12 pmalternative:
I note you have more than one feebase/feerate per channel so depends how you want to parse it out.Code: Select all
HTTPRequest>https://1ml.com/channel?json=true,,GET,,sJSON JSONParse>sJSON,$..channel_id,ChannelID JSONParse>sJSON,$..fee_base_msat,feebase JSONParse>sJSON,$..fee_rate_milli_msat,feerate
Eg feerate for node1_policy:Code: Select all
JSONParse>sJSON,$..node1_policy.fee_rate_milli_msat,feerate

-
- Newbie
- Posts: 4
- Joined: Sat Apr 21, 2007 10:00 am
Re: Help with JSONPARSE
Thanks both! I think I prefer hagchr's method but both work. I realized I was looking at an anonymous array but was unsure of the syntax required to parse the array elements.
I am now able to do what I wanted.
Thanks again.
I am now able to do what I wanted.
Thanks again.