Menu

Use Xidel to check validity of JSON fiel

Help
2021-09-26
2021-11-24
  • Michael Simpson

    Michael Simpson - 2021-09-26

    First of all, I have to say that the readme.txt that came with Xidel zip file was ....... extensive.
    So extensive that I couldn't find what I was actually after.
    I'm running Xidel under Windows, and would like to call it in a simple way so that it checks whether the JSON code in the file is valid or not.
    I tried the following

    "h:\xidel\xidel.exe" -s jpb172_swagger.json -e "$json" > xidel_output.json

    which worked fine inasmuch as xidel_output.json was "pretty formatted"

    However, when I deliberately introduced an error into the JSON input file, xidel_output.txt was empty (as expected) but I also received all this verbage

    Error:
    jerr:JNDY0021: value not allowed at (tkCurlyBraceOpen) in {
    Possible backtrace:
    $00538A95: perhaps Q{http://jsoniq.org/functions}object + 3541 ? but unlikely
    $004360E1: perhaps ? ? but unlikely
    $00436176: perhaps ? ? but unlikely
    $00437DAF: perhaps ? ? but unlikely
    $00435544: perhaps ? ? but unlikely
    $00435090: perhaps ? ? but unlikely
    $0043F2B0: perhaps ? ? but unlikely

    Call xidel with --trace-stack to get an actual backtrace

    How do I redirect this to a NUL (or whatever it's called). I tried

    "h:\xidel\xidel.exe" -s jpb172_swagger.json -e "$json" > xidelt_output.json >1 error_results

    but that didn't seem to help. Any suggestions ?

     
  • Reino

    Reino - 2021-09-26

    Hello Michael,

    This is more of a cmd question than a question about xidel, but no matter.
    You're probably looking for -e "$json" 2>NUL.

     
  • Anonymous

    Anonymous - 2021-10-08

    Reino. Sorry to have been so slow in acknowledging your answer (which did the trick for me). I think I had a blank after the 2> (either that or 2 >), can'r remember. Be that as it may, the final line I ran was

    xidel_exe' -s input_file_to_check -e "$json" 1>NUL 2>dummy_output_file

    If dummy_output_file is empty, then the input file was well-.formed.
    Thanks again (and apologies again)

    Michael

     
  • Benito van der Zander

    It does not really work.

    If you have an invalid JSON like {"a": 1, } or {"a": 0001 }, it is also loaded

    You need the --input-format json-strict option to actually check the validity

     
  • Anonymous

    Anonymous - 2021-11-23

    Thank you for your suggestion. Just so we're on the same page, is this what you meant?

    @ECHO OFF
    del "H:\A_MS_exe\valbuddy.json" /q 2>NUL
    "H:\Xidel\Xidel.exe" -s "H:\ICA\PRIV.JSON\JSON_FORMATTED\JPB113_SCHEMA_REQUEST.JSON" -e input-format json-strict "$json" 1>NUL 2>"H:\A_MS_exe\json_format_results.txt"
    
     
  • Anonymous

    Anonymous - 2021-11-23

    More like this:

    "H:\Xidel\Xidel.exe" --input-format json-strict -s "H:\ICA\PRIV.JSON\JSON_FORMATTED\JPB113_SCHEMA_REQUEST.JSON" -e "$json" 1>NUL 2>"H:\A_MS_exe\json_format_results.txt"

    And this would be faster:

    "H:\Xidel\Xidel.exe" --input-format json-strict -s "H:\ICA\PRIV.JSON\JSON_FORMATTED\JPB113_SCHEMA_REQUEST.JSON" -e "count($json)" 1>NUL 2>"H:\A_MS_exe\json_format_results.txt"

     
  • Anonymous

    Anonymous - 2021-11-24

    Thank you. I implemented your second suggestion.

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.