-2

when i read json data from SFTP server i'm getting data as bytes format which i shown below

b'{"FirstName":"fName'N "}'

here after end of the value there is a single quote.because of that i'm unable to convert to dict..is there any solution how we get string as output

sri
  • 21
  • 3
  • 1
    Does this answer your question? [How to parse JSON in Python?](https://stackoverflow.com/questions/7771011/how-to-parse-json-in-python) – mkrieger1 Sep 15 '20 at 14:44
  • 1
    Or https://stackoverflow.com/questions/606191/convert-bytes-to-a-string – mkrieger1 Sep 15 '20 at 14:44

1 Answers1

1

First, convert the byte format to string:

stringInput = b'{"FirstName":"fName"}'.decode('ascii')

then, use the json package to parse the JSON.

import json
dictInput = json.loads(stringInput)
  • Welcome to Stack Overflow! Questions as basic as this usually have already been asked and answered. In such cases, flagging (or voting, once you have the reputation) to close is the correct course of action. Please don't answer duplicates. – Pranav Hosangadi Sep 15 '20 at 14:51
  • once check the input string u hv taken.. in my byte string value is ending with single quotes – sri Sep 15 '20 at 14:59