= Querying Caches with Protobuf Schemas
{brandname} automatically converts JSON to Protobuf so that you can read and
write cache entries in JSON format and use Protobuf schemas to query them.

For example, consider the following JSON documents:

.`lukecage.json`
----
{
  "_type":"org.infinispan.rest.search.entity.Person",
  "id":2,
  "name":"Luke",
  "surname":"Cage",
  "gender":"MALE",
  "address":{"street":"38th St","postCode":"NY 11221"},
  "phoneNumbers":[{"number":4444},{"number":5555}]
}
----

.`jessicajones.json`
----
{
  "_type":"org.infinispan.rest.search.entity.Person",
  "id":1,
  "name":"Jessica",
  "surname":"Jones",
  "gender":"FEMALE",
  "address":{"street":"46th St","postCode":"NY 10036"},
  "phoneNumbers":[{"number":1111},{"number":2222},{"number":3333}]
}
----

.`matthewmurdock.json`
----
{
  "_type":"org.infinispan.rest.search.entity.Person",
  "id":3,
  "name":"Matthew",
  "surname":"Murdock",
  "gender":"MALE",
  "address":{"street":"57th St","postCode":"NY 10019"},
  "phoneNumbers":[]
}
----

Each of the preceding JSON documents contains:

* A `_type` field that identifies the Protobuf message to which the JSON document corresponds.
* Several fields that correspond to datatypes in the `person.proto` schema.

.Procedure

. Navigate to the `pcache` cache.
+
----
[//containers/default/caches]> cd pcache
----
+
. Add each JSON document as an entry to the cache, for example:
+
----
[//containers/default/caches/pcache]> put --encoding=application/json --file=jessicajones.json jessicajones
[//containers/default/caches/pcache]> put --encoding=application/json --file=matthewmurdock.json matthewmurdock
[//containers/default/caches/pcache]> put --encoding=application/json --file=lukecage.json lukecage
----
+
. Verify that the entries exist.
+
----
[//containers/default/caches/pcache]> ls
lukecage
matthewmurdock
jessicajones
----
+
. Query the cache to return entries from the Protobuf `Person` entity where the gender datatype is `MALE`.
+
----
[//containers/default/caches/pcache]> query "from org.infinispan.rest.search.entity.Person p where p.gender = 'MALE'"
{
  "total_results" : 2,
  "hits" : [ {
    "hit" : {
      "_type" : "org.infinispan.rest.search.entity.Person",
      "id" : 2,
      "name" : "Luke",
      "surname" : "Cage",
      "gender" : "MALE",
      "address" : {
        "street" : "38th St",
        "postCode" : "NY 11221"
      },
      "phoneNumbers" : [ {
        "number" : "4444"
      }, {
        "number" : "5555"
      } ]
    }
  }, {
    "hit" : {
      "_type" : "org.infinispan.rest.search.entity.Person",
      "id" : 3,
      "name" : "Matthew",
      "surname" : "Murdock",
      "gender" : "MALE",
      "address" : {
        "street" : "57th St",
        "postCode" : "NY 10019"
      }
    }
  } ]
}
----
