Parsing jbeam files.

Discussion in 'Utilities and programming' started by jankimusz, Aug 22, 2018.

  1. jankimusz

    jankimusz
    Expand Collapse

    Joined:
    Jun 12, 2016
    Messages:
    36
    I read in the documentation that .jbeam is a little modified .json, but doesn't actually say specifically how. Parsing .jbeam with a conventional .json library won't work.
    I tried nlohmans library https://github.com/nlohmann/json.

    Is there a jbeam library or something that would help me? Anything? (I know that official beamng editor built in QT can parse and export jbeam, so I will have look at the source).
     
  2. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    I think that source of NB editor is your best bet on this one.
     
  3. Masa

    Masa
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    26
    The parsing is relatively simple.

    At least before, the main differences to JSON were
    1) JBEAM allows C-style comments
    2) JBEAM does not care about commas, while JSON parsers usually requires them to be correct

    How the parsing is perhaps easiest to implement, is to convert the JBEAM to valid JSON, and then parse it with a JSON parser.

    So remove the C-style comments, and fix the commas, then parse with a JSON parser. Or alternatively, I believe you could use BeamNG's own lua parser.

    Here in this quite messy NB editor file at line around 2907 is the JBEAM parsing code currently used:
    https://github.com/RORMasa/NodeBeamEditor/blob/master/source/NodeBeam.cpp

    The file also contains old obsolete parsing and exporting code that is not in use, that you can ignore. :)

    Fixing the commas and removing the comments might be cleaner to do with regular expressions.
     
    • Informative Informative x 2
    • Like Like x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice