My raw data are plain text files where each line is a json string. For example:
{"f1": "v1", "f2": [1, 2, 3]}
{"f1": "v2", "f2": [2, 3, 4]}
I read the file into tf.Dataset
by
ds = tf.data.TextLineDataset("file_name"))
Now each element of ds
is a Tensor with dtype=tf.string
.
How do I parse the json strings?
I tried
ds.map(lambda x: json.loads(x)["f2"])
but got
TypeError: the JSON object must be str, bytes or bytearray, not 'Tensor'