Add decode_json support#695
Conversation
This PR adds decode_json support so that it is possible to use
```
values = tfio.experimental.serialization.decode_json(json, specs)
```
to decode a JSON string into a structured Tensors.
The specs field is the structured tf.TensorSpec that is necessary
to reconstruct the JSON values. The reason being JSON could be intepreted
differently in lists:
```
{
"v": [1, 2, 3]
}
```
could be considered as one Tensor of shape `(3)`, or a 3 Tensor structure within dict "v".
Note structured tf.TensorSpecs need to change list `[]` into tuple `()`
as list is not supported in structures in TensorFlow.
This PR fixes 692.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
|
/cc @noahtren |
|
Thanks so much! This is a huge help to my pipeline which includes JSON alongside a lot of other data types. So helpful to have a function to turn these into tensors. |
|
The following example does not parse the json correctly:
Gives:
However, 1-D works, for example:
Gives:
Is this desired behaviour? |
|
I think with recursion the multi-dimensional case shouldn't be too hard, unless I'm missing something. If I find the time I'll try and implement this myself. Thanks for putting in the new PR @yongtang! |
This PR adds decode_json support so that it is possible to use
```
values = tfio.experimental.serialization.decode_json(json, specs)
```
to decode a JSON string into a structured Tensors.
The specs field is the structured tf.TensorSpec that is necessary
to reconstruct the JSON values. The reason being JSON could be intepreted
differently in lists:
```
{
"v": [1, 2, 3]
}
```
could be considered as one Tensor of shape `(3)`, or a 3 Tensor structure within dict "v".
Note structured tf.TensorSpecs need to change list `[]` into tuple `()`
as list is not supported in structures in TensorFlow.
This PR fixes 692.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This PR adds decode_json support so that it is possible to use
to decode a JSON string into a structured Tensors.
The specs field is the structured tf.TensorSpec that is necessary
to reconstruct the JSON values. The reason being JSON could be intepreted
differently in lists:
could be considered as one Tensor of shape
(3), or a 3 Tensor structure within dict "v".Note structured tf.TensorSpecs need to change list
[]into tuple()as list is not supported in structures in TensorFlow.
This PR fixes #692.
Signed-off-by: Yong Tang yong.tang.github@outlook.com