Working with JSON
Lesson 1: What is JSON?
What is JSON?
- JSON stands for JavaScript Object Notation.
- It is a lightweight data-interchange format that is a textual representation of data that is usually in memory. It is native to JavaScript and should be recognizable to C-style programmers. It is very human-readable, and machines can easily parse and generate it.
- JSON is used to serialize data from memory to store it or to send it to a different application. In other words, to interchange data. Its format is common and recognizable to programmers, in that it has nested objects and arrays.
- The JSON object is a set of name value pairs. Values are wrapped in curly brackets {}, are comma separated, and can be strings, numbers, arrays or Booleans. Values can also be nested.
Comparing JSON to XML
- JSON is a bit lighter to read
- There are no open/close tags in JSON
- The name of every element is listed just once in JSON
- JSON supports arrays that XML does not
- Both are human readable
- Both are hierarchical (nested objects)
- XML is more extensive, standardized and supported
- JSON is quicker and less standardized
- JSON is easier to parse
- JSON is native to JavaScript
There are three ways to use JSON in DataFlex:
- cJsonObject
- Manually parses and generates JSON
- Will serialize or deserialize structs and arrays into JSON
- cJsonHttpTransfer
- To communicate JSON over HTTP
- Web Services support
- Have built in JSON support
- Every web service made in DataFlex can be called using SOAP and XML, but the same service can also be called using JSON.
- This is not Restful JSON services