• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

JSON Data types and Properties Overview

Note

This feature is available in NCache Enterprise and Professional editions.

JSON is a human-readable lightweight syntax for sharing data. It is structured and formatted for machines to parse effortlessly and for data exchange to occur conveniently and seamlessly. JSON has the JsonObject (an unordered name/value pair as attributes) as a basic structure.

Additionally, using JSON requires JSON serialization and it is most commonly used when dealing with multilingual applications or applications that interact with numerous documents. If you have a complete object, you can use a NewtonSoft Serializer to procure a JSON string and add it as an object (which you can read more about in our Administrators' Guide). Alternatively, NCache provides an API to construct a JSON object. Basically, NCache lets you add data that represents JSON into your cache. However, if you are dealing with documents, as we've discussed previously, you can add the documents to the cache directly.

NCache allows users the flexibility of retrieving any custom class data in your cache as JSON. Moreover, data can be added as JSON and fetched as a custom class, provided that the attributes represent the properties of the custom class. Data being JSON serialized, when retrieved by the user as JSON, is parsed by NCache and provided to you as either of the following according to your requirement:

  • JsonObject
  • JsonNull

These classes are derived from an abstract class called JsonValueBase.

Consider a .NET class Product containing data of products. When added with the JsonObject, the class attributes, e.g., ProductName and ProductID, etc., will be the attributes of the JsonObject. Given below is the data of a .NET class containing the following properties:

Product product = new Product();
product.ProductID = 1001;
product.ProductName = "Chai";
product.Category = "Beverages"

The JSON equivalent of the given data when added as JsonObject will be a string containing all the attributes and is displayed as follows:

{
    "ProductID" : 1001,
    "ProductName" : "Chai",
    "Category" : "Beverages"
}

Moreover, you can provide a string containing JSON data and parse it to get JsonValueBase in return. It will parse this string and identify the data type. Let us get a closer look at all these classes provided by NCache.

JsonObject
This class represents JObject in JSON standards in NCache’s domain. Just as a JObject contains name/value pairs (referring to the attribute). This class also contains the string and JsonValueBase key-value pairs.

JsonNull
This class represents a null value in JSON standards. It also maps null values in NCache’s domain to null values in JSON standards.

JsonObject can be added with a CacheItem in the cache. The CacheItem is a class that represents a cached item, including its various properties. The CacheItem can provide JsonObject with many functionalities, such as:

  • Cache Dependencies (Enterprise only)
  • Tags (Enterprise only)
  • NamedTags (Enterprise only)
  • Groups (Enterprise only)
  • Expiration

Various operations performed on the cache using the classes mentioned above are explained in the successive chapters.

See Also

Using JsonObject in Cache
Cache Serialization Format

Back to top Copyright © 2017 Alachisoft