Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - problem parsing JSON with pps library: (16 Items)
   
problem parsing JSON with pps library  
I am trying to parse a JSON formatted file with the pps library (pps.h) but I am having an issue parsing the entire file
. It seem as though the pps_decoder_t data structure is limited to only 40 nodes, which isn't enough to parse the entire
 file. Even if I change the global definition PPS_DECODER_INITIAL_NODES from 40 to 100 the function 
pps_decoder_parse_pps_str() will still not populate more then 40 node. 

I haven't been able to find a way around this. Can someone please point me in the right direction as to what is needed 
to parse the entire file?

Thanks.
RE: problem parsing JSON with pps library  
It is limited only by available memory (which on a 1GB device may be limited to 40 nodes but that's another story).

I gave it the following which is 1000ish and it encodes it just fine.

{"a1":[1,2,3,4,5,6,7,8,9,10],"a2":[1,2,3,4,5,6,7,8,9,10],"a3":[1,2,3,4,5,6,7,8,9,10],"a4":[1,2,3,4,5,6,7,8,9,10],"a5":[1
,2,3,4,5,6,7,8,9,10],"a6":[1,2,3,4,5,6,7,8,9,10],"a7":[1,2,3,4,5,6,7,8,9,10],"a8":[1,2,3,4,5,6,7,8,9,10],"a9":[1,2,3,4,5
,6,7,8,9,10],"a10":[1,2,3,4,5,6,7,8,9,10],"a11":[1,2,3,4,5,6,7,8,9,10],"a12":[1,2,3,4,5,6,7,8,9,10],"a13":[1,2,3,4,5,6,7
,8,9,10],"a14":[1,2,3,4,5,6,7,8,9,10],"a15":[1,2,3,4,5,6,7,8,9,10],"a16":[1,2,3,4,5,6,7,8,9,10],"a17":[1,2,3,4,5,6,7,8,9
,10],"a18":[1,2,3,4,5,6,7,8,9,10],"a19":[1,2,3,4,5,6,7,8,9,10],"a20":[1,2,3,4,5,6,7,8,9,10],"a21":[1,2,3,4,5,6,7,8,9,10]
,"a22":[1,2,3,4,5,6,7,8,9,10],"a23":[1,2,3,4,5,6,7,8,9,10],"ab1":[1,2,3,4,5,6,7,8,9,10],"ab2":[1,2,3,4,5,6,7,8,9,10],"
ab3":[1,2,3,4,5,6,7,8,9,10],"ab4":[1,2,3,4,5,6,7,8,9,10],"ab5":[1,2,3,4,5,6,7,8,9,10],"ab6":[1,2,3,4,5,6,7,8,9,10],"ab7"
:[1,2,3,4,5,6,7,8,9,10],"ab8":[1,2,3,4,5,6,7,8,9,10],"ab9":[1,2,3,4,5,6,7,8,9,10],"ab10":[1,2,3,4,5,6,7,8,9,10],"ab11":
[1,2,3,4,5,6,7,8,9,10],"ab12":[1,2,3,4,5,6,7,8,9,10],"ab13":[1,2,3,4,5,6,7,8,9,10],"ab14":[1,2,3,4,5,6,7,8,9,10],"ab15":
[1,2,3,4,5,6,7,8,9,10],"ab16":[1,2,3,4,5,6,7,8,9,10],"ab17":[1,2,3,4,5,6,7,8,9,10],"ab18":[1,2,3,4,5,6,7,8,9,10],"ab19":
[1,2,3,4,5,6,7,8,9,10],"ab20":[1,2,3,4,5,6,7,8,9,10],"ab21":[1,2,3,4,5,6,7,8,9,10],"ab22":[1,2,3,4,5,6,7,8,9,10],"ab23":
[1,2,3,4,5,6,7,8,9,10],"ab1":[1,2,3,4,5,6,7,8,9,10],"ab2":[1,2,3,4,5,6,7,8,9,10],"ab3":[1,2,3,4,5,6,7,8,9,10],"ab4":[1,2
,3,4,5,6,7,8,9,10],"ab5":[1,2,3,4,5,6,7,8,9,10],"ab6":[1,2,3,4,5,6,7,8,9,10],"ab7":[1,2,3,4,5,6,7,8,9,10],"ab8":[1,2,3,4
,5,6,7,8,9,10],"ab9":[1,2,3,4,5,6,7,8,9,10],"ab10":[1,2,3,4,5,6,7,8,9,10],"ab11":[1,2,3,4,5,6,7,8,9,10],"ab12":[1,2,3,4,
5,6,7,8,9,10],"ab13":[1,2,3,4,5,6,7,8,9,10],"ab14":[1,2,3,4,5,6,7,8,9,10],"ab15":[1,2,3,4,5,6,7,8,9,10],"ab16":[1,2,3,4,
5,6,7,8,9,10],"ab17":[1,2,3,4,5,6,7,8,9,10],"ab18":[1,2,3,4,5,6,7,8,9,10],"ab19":[1,2,3,4,5,6,7,8,9,10],"ab20":[1,2,3,4,
5,6,7,8,9,10],"ab21":[1,2,3,4,5,6,7,8,9,10],"ab22":[1,2,3,4,5,6,7,8,9,10],"ab23":[1,2,3,4,5,6,7,8,9,10],"abb1":[1,2,3,4,
5,6,7,8,9,10],"abb2":[1,2,3,4,5,6,7,8,9,10],"abb3":[1,2,3,4,5,6,7,8,9,10],"abb4":[1,2,3,4,5,6,7,8,9,10],"abb5":[1,2,3,4,
5,6,7,8,9,10],"abb6":[1,2,3,4,5,6,7,8,9,10],"abb7":[1,2,3,4,5,6,7,8,9,10],"abb8":[1,2,3,4,5,6,7,8,9,10],"abb9":[1,2,3,4,
5,6,7,8,9,10],"abb10":[1,2,3,4,5,6,7,8,9,10],"abb11":[1,2,3,4,5,6,7,8,9,10],"abb12":[1,2,3,4,5,6,7,8,9,10],"abb13":[1,2,
3,4,5,6,7,8,9,10],"abb14":[1,2,3,4,5,6,7,8,9,10],"abb15":[1,2,3,4,5,6,7,8,9,10],"abb16":[1,2,3,4,5,6,7,8,9,10],"abb17":
[1,2,3,4,5,6,7,8,9,10],"abb18":[1,2,3,4,5,6,7,8,9,10],"abb19":[1,2,3,4,5,6,7,8,9,10],"abb20":[1,2,3,4,5,6,7,8,9,10],"
abb21":[1,2,3,4,5,6,7,8,9,10],"abb22":[1,2,3,4,5,6,7,8,9,10],"abb23":[1,2,3,4,5,6,7,8,9,10]}

Perhaps your JSON is wrong?

________________________________________
From: Mark Tyndall [community-noreply@qnx.com]
Sent: Thursday, February 28, 2013 4:41 PM
To: general-community
Subject: problem parsing JSON with pps library

I am trying to parse a JSON formatted file with the pps library (pps.h) but I am having an issue parsing the entire file
. It seem as though the pps_decoder_t data structure is limited to only 40 nodes, which isn't enough to parse the entire
 file. Even if I change the global definition PPS_DECODER_INITIAL_NODES from 40 to 100 the function 
pps_decoder_parse_pps_str() will still not populate more then 40 node.

I haven't been able to find a way around this. Can someone please point me in the right direction as to what is needed 
to parse the entire file?

Thanks.



_______________________________________________

General
http://community.qnx.com/sf/go/post99619
To cancel your subscription to this discussion, please e-mail general-community-unsubscribe@community.qnx.com
Re: RE: problem parsing JSON with pps library  
My looks to be about the same length as your. The JSON file may not not be formated correctly but theres nothing I can 
do about the format since I don't control that. I'm pretty much stuck with parsing what is there. 

If you were able to parse a file of that length then there's defiantly something wrong. 

Thanks
RE: RE: problem parsing JSON with pps library  
The question would be one of validity, not formatting.  If it's not legal JSON then you'd have problems whatever the 
length.  Can you provide the JSON you're trying to parse.

________________________________________
From: Mark Tyndall [community-noreply@qnx.com]
Sent: Friday, March 01, 2013 8:53 AM
To: general-community
Subject: Re: RE: problem parsing JSON with pps library

My looks to be about the same length as your. The JSON file may not not be formated correctly but theres nothing I can 
do about the format since I don't control that. I'm pretty much stuck with parsing what is there.

If you were able to parse a file of that length then there's defiantly something wrong.

Thanks


Re: RE: RE: problem parsing JSON with pps library  
[n]@status
BatteryInfo:json:{"BatteryState":"READY","NumOfBattery":1,"ActiveBattery":0,"BatteryStatus":[{"BatteryName":"No Name","
BatteryPresent":"YES","BatteryId":256,"StateOfBattery":"OK","StateOfCharge":99,"StateOfHealth":138,"BatteryVoltage":4317
,"TimeToEmpty":6143,"TimeToFull":65535,"AvailableEnergy":80000000,"AverageCurrent":0,"AveragePower":80000000,"
BatteryAlert":"NO","CycleCount":633,"Temperature":3600,"DesignCapacity":1250,"FullAvailableCap":80000000,"FullChargeCap"
:80000000,"MaxLoadCurrent":80000000,"MaxLoadTimeToEmpty":80000000,"NominalAvailableCap":80000000,"TimeToEmptyAtConstPwr"
:80000000}]}
ChargerInfo:json:{"ChargerState":"READY","NumOfSource":2,"ActiveCharger":1,"ChargerParams":[{"ChargerStatus":"CHARGING",
"MaxInputCurrent":850,"MaxChargeCurrent":1960,"ChargerName":"AC Contacts"},{"ChargerStatus":"CHARGING","MaxInputCurrent"
:500,"MaxChargeCurrent":1960,"ChargerName":"USB Host"}]}
DeviceName::
SystemInfo:json:{"SystemState":"READY","SystemVoltage":80000000,"InputCurrentMonitor":80000000,"ChargingState":"CV","
MaxSystemVoltage":4350,"MinSystemVoltage":3200,"ChargeCurrent":1960}
Version:n:1
Re: RE: RE: problem parsing JSON with pps library  
By the way it fails a NumOfSources
RE: RE: RE: problem parsing JSON with pps library  
What exactly is failing?  Are you having problems with parsing it as the subject of the post implies? i.e. 
pps_decoder_parse_pps_str fails.  Or is the issue with extracting some data?  From your last comment I'm getting the 
impression that it's an extraction problem.  It works fine for me.

________________________________________
From: Mark Tyndall [community-noreply@qnx.com]
Sent: Friday, March 01, 2013 9:16 AM
To: general-community
Subject: Re: RE: RE: problem parsing JSON with pps library

[n]@status
BatteryInfo:json:{"BatteryState":"READY","NumOfBattery":1,"ActiveBattery":0,"BatteryStatus":[{"BatteryName":"No Name","
BatteryPresent":"YES","BatteryId":256,"StateOfBattery":"OK","StateOfCharge":99,"StateOfHealth":138,"BatteryVoltage":4317
,"TimeToEmpty":6143,"TimeToFull":65535,"AvailableEnergy":80000000,"AverageCurrent":0,"AveragePower":80000000,"
BatteryAlert":"NO","CycleCount":633,"Temperature":3600,"DesignCapacity":1250,"FullAvailableCap":80000000,"FullChargeCap"
:80000000,"MaxLoadCurrent":80000000,"MaxLoadTimeToEmpty":80000000,"NominalAvailableCap":80000000,"TimeToEmptyAtConstPwr"
:80000000}]}
ChargerInfo:json:{"ChargerState":"READY","NumOfSource":2,"ActiveCharger":1,"ChargerParams":[{"ChargerStatus":"CHARGING",
"MaxInputCurrent":850,"MaxChargeCurrent":1960,"ChargerName":"AC Contacts"},{"ChargerStatus":"CHARGING","MaxInputCurrent"
:500,"MaxChargeCurrent":1960,"ChargerName":"USB Host"}]}
DeviceName::
SystemInfo:json:{"SystemState":"READY","SystemVoltage":80000000,"InputCurrentMonitor":80000000,"ChargingState":"CV","
MaxSystemVoltage":4350,"MinSystemVoltage":3200,"ChargeCurrent":1960}
Version:n:1



Re: RE: RE: RE: problem parsing JSON with pps library  
Well its failing to parse the entire file. I call pps_decoder_initialize(&decoder, NULL); then I call 
pps_decoder_parse_pps_str(&decoder, ppsBuf); passing it the decoder structure and ppsBuf which is a null terninated char
 array and has the entire file in it. After it returns I check decoder and it only has the data up to NumOfSource. The 
data I am after is in the array under ChargerParams. 
RE: RE: RE: RE: problem parsing JSON with pps library  
Use the pps_decoder functions to get data out, don't try to peek into the data structures yourself, you can't do this 
safely and even if it 'works', you are asking for things to break in future.

If you do things the official, supported way, you will probably discover all your data is there. 

________________________________________
From: Mark Tyndall [community-noreply@qnx.com]
Sent: Friday, March 01, 2013 9:40 AM
To: general-community
Subject: Re: RE: RE: RE: problem parsing JSON with pps library

Well its failing to parse the entire file. I call pps_decoder_initialize(&decoder, NULL); then I call 
pps_decoder_parse_pps_str(&decoder, ppsBuf); passing it the decoder structure and ppsBuf which is a null terninated char
 array and has the entire file in it. After it returns I check decoder and it only has the data up to NumOfSource. The 
data I am after is in the array under ChargerParams.

Re: RE: RE: RE: RE: problem parsing JSON with pps library  
I'm looking at the struct through a debugger. Why would that break things? 
RE: RE: RE: RE: RE: problem parsing JSON with pps library  
It won't break anything.  If you're poking through the data structures with the debugger (or with your code) I suspect 
the issue is that they don't work the way you believe them to work.

If you use the pps_decoder functions to get the data I suspect you'll discover it's all there.  

________________________________________
From: Mark Tyndall [community-noreply@qnx.com]
Sent: Friday, March 01, 2013 11:41 AM
To: general-community
Subject: Re: RE: RE: RE: RE: problem parsing JSON with pps library

I'm looking at the struct through a debugger. Why would that break things?



Re: RE: RE: RE: RE: RE: problem parsing JSON with pps library  
I have just tested it and I am able to request data past "NumOfSource" but still unable to get the data I am really 
after which is the second entry of the array under "ChargerParams". If I look for "ChargerName" I am only able to see 
the data in the first entry of the array.  
RE: RE: RE: RE: RE: RE: problem parsing JSON with pps library  
How are you doing it?  You are using the pps_decoder_* functions?


________________________________________
From: Mark Tyndall [community-noreply@qnx.com]
Sent: Friday, March 01, 2013 12:05 PM
To: general-community
Subject: Re: RE: RE: RE: RE: RE: problem parsing JSON with pps library

I have just tested it and I am able to request data past "NumOfSource" but still unable to get the data I am really 
after which is the second entry of the array under "ChargerParams". If I look for "ChargerName" I am only able to see 
the data in the first entry of the array.

Re: RE: RE: RE: RE: RE: RE: problem parsing JSON with pps library  
pps_decoder_push(&decoder, "ChargerInfo");		
pps_decoder_push_array(&decoder, "ChargerParams");	
pps_decoder_get_string(&decoder, "ChargerStatus", &svalue);
RE: RE: RE: RE: RE: RE: RE: problem parsing JSON with pps library  
Your data looks like this:

ChargerInfo:json:{"ChargerState":"READY","NumOfSource":2,"ActiveCharger":1,"ChargerParams":[{"ChargerStatus":"CHARGING",
"MaxInputCurrent":850,"MaxChargeCurrent":1960,"ChargerName":"AC Contacts"},{"ChargerStatus":"CHARGING","MaxInputCurrent"
:500,"MaxChargeCurrent":1960,"ChargerName":"USB Host"}]}

So, when you call:

pps_decoder_push(&decoder, "ChargerInfo");

you've now descended into the object with the name "ChargerInfo".  For what it's worth, anytime you push into a 
composite object such as an array or object you are positioned at its first element, in this case a string called "
ChargerState".

When you then call:

pps_decoder_push_array(&decoder, "ChargerParams");

you have now pushed/descended into the array with the name "ChargerParams".  This is a two element array and you are 
positioned on it's first element.

Calling:

pps_decoder_get_string(&decoder, "ChargerStatus", &svalue);

will give you an error since arrays don't have elements with names, you can't get the "ChargerStatus" property of an 
array.

So instead.

To push into the first object in the array, you'd execute

pps_decoder_push(&decoder, NULL);

specifying NULL just means the current element, as array elements don't have names, this is all you can do.  
Alternatively, if you just wanted the second element you could first call pps_decoder_next to advance to the second 
element.

Having pushed into the first element of the array, you can now get the ChargerStatus value as you were trying to get 
before.  Once you've extracted all the data you want from the first element of the array, you can pop out of it:

pps_decoder_pop(&decoder);

at which point you are now pointing at the second element of the array (another object).  If you want to get the "
ChargerStatus" from this, you must again push into it etc:

pps_decoder_push(&decoder, NULL);
pps_decoder_get_string(&decoder, "ChargerStatus", &svalue);


It might a bit of getting use to but is actually pretty simple.



________________________________________
From: Mark Tyndall [community-noreply@qnx.com]
Sent: Friday, March 01, 2013 2:43 PM
To: general-community
Subject: Re: RE: RE: RE: RE: RE: RE: problem parsing JSON with pps library

pps_decoder_push(&decoder, "ChargerInfo");
pps_decoder_push_array(&decoder, "ChargerParams");
pps_decoder_get_string(&decoder, "ChargerStatus", &svalue);



Re: RE: RE: RE: RE: RE: RE: RE: problem parsing JSON with pps library  
Thank you. That makes much more sense than the PPS API documentation. I will try this and see how it goes.