nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
42.01k stars 6.63k forks source link

Parse error on valid JSON file #4028

Closed pedro-vicente closed 1 year ago

pedro-vicente commented 1 year ago

Description

I have this error while parsing a valid JSON file

[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal

{ "SitNum": "344", "Message": [ "/00004 00000/7250/22 045 1359", "/344/3660/01", "/7255/+50660.0 999.9 +99.99/22 045 1244 05.16/22 045 1244 05.17/01", "/09C3E70D34F17800081A6662000F1200000BFFF003FFFFFFE50", "/0/9A749C3E70D100078900000", "/38.30/02/02/002", "/409 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000", "/725501 000000 000000 000000 000000 000000 000000 000000 000000", "000000 000000 000000 000000 000000 000000 000000 000000", "/LASSIT", "/ENDMSG" ], "InputMEOSolution": [ [ { "SolId": "15993" }, { "InMsgId": "210266" }, { "SourceId": "7255" }, { "LutSolutionId": "SQL_NULL_DATA" }, { "DataType": "0" }, { "BeaconMessageType": "SQL_NULL_DATA" }, { "BeaconMessageValid": "SQL_NULL_DATA" }, { "BcnId36": "SQL_NULL_DATA" }, { "BcnId30": "SQL_NULL_DATA" }, { "BcnId15": "9A749C3E70D1000" }, { "FrameSync": "SQL_NULL_DATA" }, { "NumBursts": "1" }, { "NumPackets": "2" }, { "NumSatellites": "SQL_NULL_DATA" }, { "NumPacketsUnUsed": "SQL_NULL_DATA" }, { "SatelliteIds": "409 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000" }, { "SourceAntennaIds": "725501 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 " }, { "DOP": "SQL_NULL_DATA" }, { "TimeFirst": "2022-02-14 12:44:05.160" }, { "TimeLast": "2022-02-14 12:44:05.170" }, { "Latitude": "SQL_NULL_DATA" }, { "Longitude": "SQL_NULL_DATA" }, { "Altitude": "SQL_NULL_DATA" }, { "FreqBias": "50660.0" }, { "FbiasDev": "999.89999999999998" }, { "FreqDrift": "99.989999999999995" }, { "QualityFactor": "SQL_NULL_DATA" }, { "Iterations": "SQL_NULL_DATA" }, { "AverageCN0": "38.299999999999997" }, { "MinimumCN0": "SQL_NULL_DATA" }, { "MaximumCN0": "SQL_NULL_DATA" }, { "EEMajor": "SQL_NULL_DATA" }, { "EEMinor": "SQL_NULL_DATA" }, { "EEHeading": "SQL_NULL_DATA" }, { "EERadius": "SQL_NULL_DATA" }, { "EEArea": "SQL_NULL_DATA" }, { "TimeSolutionGenerated": "SQL_NULL_DATA" }, { "TimeSolutionAdded": "2023-05-08 22:47:24.137" }, { "SitFunc": "344" }, { "MsgNum": "4" }, { "QualityIndicator": "SQL_NULL_DATA" }, { "NumAntennas": "2" }, { "Srr": "SQL_NULL_DATA" }, { "PositionConfFlag": "SQL_NULL_DATA" }, { "SortId": "SQL_NULL_DATA" }, { "SortType": "SQL_NULL_DATA" }, { "Distance": "SQL_NULL_DATA" }, { "ExpectedHorzError": "SQL_NULL_DATA" }, { "LutName": "SQL_NULL_DATA" }, { "MsgTime": "SQL_NULL_DATA" }, { "FileTime": "SQL_NULL_DATA" }, { "BcnId51": "09C3E70D34F17800081A6662000F1200000BFFF003FFFFFFE50" }, { "BcnId23": "9A749C3E70D100078900000" }, { "NumBCHErrs": "0" }, { "NumNetworkedAntennas": "2" } ] ], "SitHeaderIn": [ [ { "InMsgId": "210266" }, { "CircuitId": "0" }, { "ComDataId": "0" }, { "SitCnt": "1" }, { "ComSiteName": "CHMCC" }, { "CurMsgNum": "4" }, { "OrgMsgNum": "0" }, { "ReportMcc": "7250" }, { "SitNum": "344" }, { "SitNumType": " " }, { "DestMcc": "3660" }, { "ItemNum": "1" }, { "SitNumEMS": "SQL_NULL_DATA" }, { "CmdDisp": "SQL_NULL_DATA" }, { "CmdMsgNum": "SQL_NULL_DATA" } ] ], "InputMessage": [ [ { "InMsgId": "210266" }, { "MsgName": "" }, { "Complete": "1" }, { "Error": "0" }, { "Test": "0" }, { "Hold": "0" }, { "ComSiteName": "CHMCC" }, { "ComSitePathName": "FTP" }, { "TableName": "InputMEOSolution" }, { "AddTime": "2023-05-08 22:47:13.677" }, { "DoneTime": "2023-05-08 22:47:24.980" } ] ], "InputProcess": [ [ { "InProcId": "180640" }, { "InMsgId": "210266" }, { "MsgName": "" }, { "ComSiteName": "CHMCC" }, { "AddTime": "2023-05-08 22:47:24.980" }, { "SubsysId": "MALT" }, { "SubsysDisp": " " }, { "SubsysBegTm": "SQL_NULL_DATA" }, { "SubsysEndTm": "SQL_NULL_DATA" } ] ] }

Reproduction steps

copy/paste JSON above to a file read JSON from file using code below

Expected vs. actual results

[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal

Minimal code example

read the file

 std::filesystem::path path = <some path>
      try
      {
        std::ifstream ifs(path);
        assert(ifs.is_open() == true);
        nlohmann::json js = nlohmann::json::parse(ifs);
      }
      catch (const std::exception& e)
      {
        SPDLOG_ERROR(e.what());
      }

Error messages

No response

Compiler and operating system

Visual Studio 2022, Windows

Library version

3.11.2

Validation

pedro-vicente commented 1 year ago

this was an error in parsing another file (hidden) that had the same name (except for the "." as first character)

gregmarr commented 1 year ago

@nlohmann This exact error happens enough that I'm wondering if there should be a more specific error message for it, such as "Error attempting to parse an empty input, check that your input string or stream contains the expected JSON."

nlohmann commented 1 year ago

@gregmarr Yes, I also think so.