Implementation:Tensorflow Serving FillPredictRequestFromJson
| Knowledge Sources | |
|---|---|
| Domains | Data_Serialization, API_Design |
| Last Updated | 2026-02-13 17:00 GMT |
Overview
Concrete tool for parsing JSON request bodies into PredictRequest protobufs with typed TensorProto values, provided by the json_tensor module.
Description
FillPredictRequestFromJson() is the primary entry point for JSON-to-tensor conversion. It:
- Parses the JSON string using RapidJSON
- Extracts the optional signature_name field
- Determines input format (row vs columnar) based on top-level key ("instances" or "inputs")
- Delegates to FillTensorMapFromInstancesList() (row) or FillTensorMapFromInputsMap() (columnar)
- These call FillTensorProto() and AddValueToTensor() for type-specific tensor population
The function uses a get_tensorinfo_map callback to look up tensor type information from the model's SignatureDef, ensuring values are converted to the correct DT_* type.
Usage
Called internally by HttpRestApiHandler::ProcessPredictRequest(). Not called directly by users; invoked automatically when processing REST predict requests.
Code Reference
Source Location
- Repository: tensorflow/serving
- File: tensorflow_serving/util/json_tensor.cc
- Lines: L653-705 (FillPredictRequestFromJson), L519-607 (FillTensorMapFromInstancesList), L609-649 (FillTensorMapFromInputsMap), L392-436 (FillTensorProto), L290-342 (AddValueToTensor)
- Header: tensorflow_serving/util/json_tensor.h L145-150
Signature
tensorflow::Status FillPredictRequestFromJson(
const absl::string_view json,
const std::function<
tensorflow::Status(
const string& signature_name,
::google::protobuf::Map<string, tensorflow::TensorInfo>* infomap
)>& get_tensorinfo_map,
PredictRequest* request,
JsonPredictRequestFormat* format
);
Import
#include "tensorflow_serving/util/json_tensor.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| json | string_view | Yes | Raw JSON request body |
| get_tensorinfo_map | function | Yes | Callback returning tensor type info for a signature |
| format | JsonPredictRequestFormat* | Yes | Output indicator (kRow or kColumnar) |
Outputs
| Name | Type | Description |
|---|---|---|
| request | PredictRequest* | Populated proto with inputs map of TensorProto values |
| format | JsonPredictRequestFormat | kRow for "instances" format, kColumnar for "inputs" format |
Usage Examples
Row Format Request
curl -d '{"instances": [[1.0, 2.0, 3.0, 4.0]]}' \
http://localhost:8501/v1/models/mnist:predict
Columnar Format Request
curl -d '{"inputs": {"images": [[1.0, 2.0, 3.0, 4.0]]}}' \
http://localhost:8501/v1/models/mnist:predict
With Signature Name
curl -d '{
"signature_name": "predict_images",
"instances": [[1.0, 2.0, 3.0, 4.0]]
}' http://localhost:8501/v1/models/mnist:predict