Watch keynotes, product sessions, workshops, and more from Google I/O See playlist

Convert JSON-encoded Example records to binary protocol buffer strings.

This op converts JSON-serialized tf.train.Example (maybe created with json_format.MessageToJson, following the standard JSON mapping) to a binary-serialized tf.train.Example (equivalent to Example.SerializeToString()) suitable for conversion to tensors with

Here is a tf.train.Example proto:

example = tf.train.Example(
          "a": tf.train.Feature(
                  value=[1, 1, 3]))}))

Here it is converted to JSON:

from google.protobuf import json_format
example_json = json_format.MessageToJson(example)
  "features": {
    "feature": {
      "a": {
        "int64List": {
          "value": [

This op converts the above json string to a binary proto:

example_binary =

The OP works on string tensors of andy shape:[
    [example_json, example_json],
    [example_json, example_json]]).shape.as_list()
[2, 2]

This resulting binary-string is equivalent to Example.SerializeToString(), and can be converted to Tensors using and related functions:
  features = {'a':[3], dtype=tf.int64)})
{'a': <tf.Tensor: shape=(2, 3), dtype=int64, numpy=
 array([[1, 1, 3],
        [1, 1, 3]])>}

json_examples A string tensor containing json-serialized tf.Example protos.
name A name for the op.

A string Tensor containing the binary-serialized tf.Example protos.

tf.errors.InvalidArgumentError: If the JSON could not be converted to a tf.Example