>Hi all,
>
>In discussion with another developer about re-doing a system. This system interacted with a document database and the integration with the VFP app was done with calls that always returned an xml string. The other developer had mentioned using json to return back data from the server.
>
>I have done the wikipedia lookup and have an idea what json data looks like but have some questions:
>
>1) are their json parsers out there for VFP or would I have to write my own; with xml, there were the built in xml functions which I used
Yes there's one on VFPx and the West Wind Tools also
have one.
>2) does json have any advantages over xml?
Yes and no :-) JSON has the advantage that it's much easier to create and parse. XML requires a schema to deal with type information - otherwise you have no idea whether an XML node is text or a number, or date, object etc. JSON inherently includes basic type information by nature of the structure which is basically a JavaScript object graph. Everything in JSON is a property and it's relatively easy for a parser to tell the type of each property. You can easily nest in JSON.
For configuration JSON is not always great because it requires string encoding for special characters. Tabs, carriage returns/linefeeds and back slashes have to be encoded. It's easy to hand edit JSON and get it wrong because there's a character you forgot needed encoding. Some of this can be mitigated if you use a decent JSON editor (like VS Code) that provides syntax coloring.
XML also character encoding issues, but for text at least you can easily escape with CDATA sections.
JSON is more popular today and used for most Web applications as the data transport in REST style services. For FoxPro I would say JSON parsing and serializing is more reliable than XML (there is no native XML object parsing tooling and even tools like wwXML struggle because of the schema and type issues). JSON tends to be slower than some of the XML tooling. XmlToCursor and CursorAdapter are much faster than manually parsing XML or creating JSON/Parsing Json on the fly. JSON parsers are also not easy to build in FoxPro at least if you want decent performance for larger documents due to the limitations of FoxPro string functions. The parser used in the West Wind tools uses .NET to parse and then parses back into raw (EMPTY) objects which is orders of magnitude faster on large documents than a previous parser I had built in Fox code.
>3) any "gotchas" to watch out for?
see above.
The usual answer is it depends :-)
Personally I would probably opt for JSON just because it easily works with objects which is what I work with and XML doesn't make that natural. JSON is also the more 'modern' thing - but I guess we can take that with a grain of salt.