Reading from /dev/ttyACM0

I’m receiving data from a serial port in C. Some times the I got some junk data with original data. But I fixed this issue by give buffer size is high. But, I want the permanent fix.

I got some junk,

/system/bin/serialCom: {“jsonrpc”: “2.0”, “m 񧮽Nծ 񧮸,

char data_pac[300];

read(serialfd, pac, 300);

system/bin/serialCom: SERIAL: Received:{"jsonrpc": "2.0", "method": "notifyMotorTemperature", "params": {"motorTemperature": "25.170000"}} /system/bin/serialCom: {"jsonrpc": "2.0", "method": "notifyFrontLightType", "params": {"frontLightType": "2"}} /system/bin/serialCom: {"jsonrpc": "2.0", "method": "notifyFrontLightMode", "params": {"frontLightMode": "1"}} /system/bin/serialCom: {"jsonrpc": "2.0", "m 񧮽Nծ 񧮸, 

After increasing the buffer size this one fixed.

char data_pac[500];

read(serialfd, pac, 500);