[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.io.decode_json_example\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/parsing_ops.py#L1147-L1229) |\n\nConvert JSON-encoded Example records to binary protocol buffer strings.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.decode_json_example`](https://www.tensorflow.org/api_docs/python/tf/io/decode_json_example), [`tf.compat.v1.io.decode_json_example`](https://www.tensorflow.org/api_docs/python/tf/io/decode_json_example)\n\n\u003cbr /\u003e\n\n tf.io.decode_json_example(\n json_examples, name=None\n )\n\n| **Note:** This is **not** a general purpose JSON parsing op.\n\nThis op converts JSON-serialized [`tf.train.Example`](../../tf/train/Example) (maybe created with\n`json_format.MessageToJson`, following the\n[standard JSON mapping](https://developers.google.com/protocol-buffers/docs/proto3#json))\nto a binary-serialized [`tf.train.Example`](../../tf/train/Example) (equivalent to\n[`Example.SerializeToString()`](../../tf/train/BytesList#SerializeToString)) suitable for conversion to tensors with\n[`tf.io.parse_example`](../../tf/io/parse_example).\n\nHere is a [`tf.train.Example`](../../tf/train/Example) proto: \n\n example = tf.train.Example(\n features=tf.train.Features(\n feature={\n \"a\": tf.train.Feature(\n int64_list=tf.train.Int64List(\n value=[1, 1, 3]))}))\n\nHere it is converted to JSON: \n\n from google.protobuf import json_format\n example_json = json_format.MessageToJson(example)\n print(example_json)\n {\n \"features\": {\n \"feature\": {\n \"a\": {\n \"int64List\": {\n \"value\": [\n \"1\",\n \"1\",\n \"3\"\n ]\n }\n }\n }\n }\n }\n\nThis op converts the above json string to a binary proto: \n\n example_binary = tf.io.decode_json_example(example_json)\n example_binary.numpy()\n b'\\n\\x0f\\n\\r\\n\\x01a\\x12\\x08\\x1a\\x06\\x08\\x01\\x08\\x01\\x08\\x03'\n\nThe OP works on string tensors of andy shape: \n\n tf.io.decode_json_example([\n [example_json, example_json],\n [example_json, example_json]]).shape.as_list()\n [2, 2]\n\nThis resulting binary-string is equivalent to [`Example.SerializeToString()`](../../tf/train/BytesList#SerializeToString),\nand can be converted to Tensors using [`tf.io.parse_example`](../../tf/io/parse_example) and related\nfunctions: \n\n tf.io.parse_example(\n serialized=[example_binary.numpy(),\n example.SerializeToString()],\n features = {'a': tf.io.FixedLenFeature(shape=[3], dtype=tf.int64)})\n {'a': \u003ctf.Tensor: shape=(2, 3), dtype=int64, numpy=\n array([[1, 1, 3],\n [1, 1, 3]])\u003e}\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|-----------------------------------------------------------------|\n| `json_examples` | A string tensor containing json-serialized `tf.Example` protos. |\n| `name` | A name for the op. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A string Tensor containing the binary-serialized `tf.Example` protos. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|---|---|\n| [`tf.errors.InvalidArgumentError`](../../tf/errors/InvalidArgumentError): If the JSON could not be converted to a `tf.Example` ||\n\n\u003cbr /\u003e"]]