Working on a new version for a native JSON parser for AVFP

Coordinator
May 1, 2015 at 2:12 PM
Edited May 1, 2015 at 2:26 PM
Me and a friend are working in a new VFP JSON parser for AVFP. These are some examples of what this new parser can do:
TEXT TO cUser NOSHOW
{
  login: 'vespina',
  fullname: 'Victor Espina',
  pwd: 1234,
  role: 25
}
ENDTEXT
oUser = json.Parse(cUser)
?oUser.fullName --> "Victor Espina"
cUser = json.Stringify(oUser)
?cUser --> 
{
  login: 'vespina', 
  fullname: 'Victor Espina', 
  pwd: '1234', 
  role: 25
}
cUsers = json.Stringify("qusers", .T.)
?cUsers --> 
{ 
  name: "qusers", 
  schema: [
           {name: 'login', type: 'C', lon: 25, dec: 0},
           {name: 'fullname', type: 'C', lon: 50, dec: 0}, 
           {name: 'pwd', type: 'C', lon: 50, dec: 0}, 
           {name: 'role', type: 'N', lon: 4, dec: 0}
          ],
  rows: [
         { login: 'vespina', fullname: 'Victor Espina', pwd: '1234', role: 25},
         { login: 'cfox', fullname: 'Claude Fox', pwd: '456', role: 1}
        ]          
}
json.parseCursor(cusers)
?reccount("qusers") -->  2
?qusers.login -->  'vespina'
cUsers = json.Stringify("qusers")   && No schema
?cUsers --> 
{ 
  name: "qusers", 
  rows: [
         { login: 'vespina', fullname: 'Victor Espina', pwd: '1234', role: 25},
         { login: 'cfox', fullname: 'Claude Fox', pwd: '456', role: 1}
        ]          
}
TEXT TO cUsers NOSHOW
[
  { login: 'vespina', role: 25},
  { login: 'cfox', role: 1},
  { login: 'jdoe', role: 10}
]
ENDTEXT
json.toCursor(cUsers, "qusers")
?reccount("qusers") --> 3
?qusers.login --> 'vespina'
If there is any feature you would like to be included in this new JSON parser, let me know on this thread and we would do our best to included it.

Victor Espina
Coordinator
May 1, 2015 at 3:08 PM
The speed, from what I've seen so far, is absolutely fantastic. I'm looking forward to playing with this!
Coordinator
May 1, 2015 at 3:19 PM
Edited May 1, 2015 at 3:20 PM
Those of you interested on testing this new parser, can download it from here:
http://www.noiqs.com/sos/json.prg
Feb 5 at 11:45 PM
Somehow someone was able to enter a numeric value which did not fit in the field and it was saved to the table by ActiveVFP. My client side script automatically parses numbers using maxlength and step values in the HTML. It may have been just a random error.

The JSON stream could not be parsed on the client side. I fixed the error in the table using PocketFox, but I couldn't fix it in the client.

In the JSON stream it had stars, which is what VFP puts when the value is too long to fit in the allocated space. The stars don't have quotes around them so the JavaScript parser chokes.
quota: ****.
Coordinator
Feb 6 at 1:54 PM
The interesting thing here would be: how the parser should handle this situation? an overflown number (*****) is not either zero nor null. Maybe the way to go here would be to raise an error at parsing time, instead of generating an invalid JSON string. What do you think ?


Victor
Feb 23 at 4:05 PM
In my opinion, the stars should just get wrapped in quotes and sent to the client as plain text so that JavaScript on the client side can parse it. I could fix this bug by parsing the JSON string and wrap sequences of asterisks after colons in quotes. Then it will be displayed on the user's screen as asterisks the same way as it would on a VFP report form. Anyone with any familiarity with VFP will know that this is an overflow.

I don`t necessarily want the code blindly fixing errors and due to the way my system is set up the person running the query may not have permission to write corrections to the corrupted table.