Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tensorflow Serving MakeJsonFromTensors

From Leeroopedia
Revision as of 13:53, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Tensorflow_Serving_MakeJsonFromTensors.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Data_Serialization, API_Design
Last Updated 2026-02-13 17:00 GMT

Overview

Concrete tool for converting TensorProto output maps to JSON response strings, provided by the json_tensor module.

Description

MakeJsonFromTensors() converts the output tensor map from a PredictResponse into a JSON string. It dispatches to:

  • MakeRowFormatJsonFromTensors() for row format ({"predictions": [...]})
  • MakeColumnarFormatJsonFromTensors() for columnar format ({"outputs": {...}})

Both use AddSingleValueAndAdvance() for type-specific value serialization. The function uses RapidJSON's PrettyWriter for output formatting. Error responses are generated by MakeJsonFromStatus() which produces {"error": "<message>"}.

Usage

Called internally by ProcessPredictRequest() after inference completes. The format parameter must match the format detected during request parsing.

Code Reference

Source Location

  • Repository: tensorflow/serving
  • File: tensorflow_serving/util/json_tensor.cc
  • Lines: L1052-1066 (MakeJsonFromTensors), L975-1026 (MakeRowFormatJsonFromTensors), L1028-1048 (MakeColumnarFormatJsonFromTensors), L888-950 (AddSingleValueAndAdvance)
  • Header: tensorflow_serving/util/json_tensor.h L259-261

Signature

tensorflow::Status MakeJsonFromTensors(
    const ::google::protobuf::Map<string, TensorProto>& tensor_map,
    JsonPredictRequestFormat format,
    string* json
);

Import

#include "tensorflow_serving/util/json_tensor.h"

I/O Contract

Inputs

Name Type Required Description
tensor_map Map<string, TensorProto> Yes Named output tensors from PredictResponse
format JsonPredictRequestFormat Yes Must match input format (kRow or kColumnar)

Outputs

Name Type Description
json string* JSON response string

Usage Examples

Row Format Response

{
    "predictions": [
        [0.1, 0.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.8, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    ]
}

Columnar Format Response

{
    "outputs": {
        "scores": [
            [0.1, 0.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            [0.0, 0.0, 0.8, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
        ]
    }
}

Error Response

{
    "error": "Model mnist not found"
}

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment