• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Hypnotist

Office of Naval Intelligence
19 Badges
Feb 28, 2016
178
0
  • Hearts of Iron IV: Together for Victory
  • BATTLETECH: Heavy Metal
  • BATTLETECH: Season pass
  • Imperator: Rome Sign Up
  • Hearts of Iron IV: Expansion Pass
  • BATTLETECH: Flashpoint
  • Hearts of Iron IV: Expansion Pass
  • Age of Wonders III
  • Hearts of Iron IV: Death or Dishonor
  • BATTLETECH
  • Hearts of Iron IV: Colonel
  • Hearts of Iron IV: Cadet
  • Pillars of Eternity
  • Crusader Kings II
  • Semper Fi
  • Hearts of Iron III Collection
  • Hearts of Iron III: Their Finest Hour
  • Hearts of Iron III
  • For the Motherland
Do json files support embedded non-code notation for change-logging and debugging? If so, does it require special syntax so the notation is not attempted to be read as instruction?

Plain english: I would like to leave change notes inside the json files I edit (original values, ranges, effects, etc.)
 
JSON does not support comments (by design).

There's nothing stopping you from having a key named "_version", "_debug", or "_comment" though, with your version number as a value. How to use it / ignore it would be up to your application logic.

Also, there's nothing stopping you from adding comments with whatever comment characters you want, if you understand that they make the JSON invalid to parsers and need to be stripped before passing the JSON to a parser.

Edit: Here's the creator of JSON on the issue:

"I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn't.

Suppose you are using JSON to keep configuration files, which you would like to annotate. Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser."​
 
Last edited:
JSON the standard does not. JSON that HBS uses, does. Modtek supports that too. Check out the comments and formatting in the bevahiorVariables folder in \BATTLETECH\BattleTech_Data\StreamingAssets\data\behaviorVariables for an example:
Code:
    {
        /* How much accuracy (0.0 - 1.0) is required to consider
           an attack that will overheat */
            "k" : "Float_AccuracyNeededForOverheatAttack",
            "v" : {
        "type" : "Float",
        "floatVal" : 0.75
            }
    },
You can use this /* COMMENT HERE */ notation in your ModTek JSON's as I did in the Better AI mod. ModTek used to not handle the HBS notations, but this was added in a few versions ago.
 
I suspect HBS is using JSON5 which does allow for comments (its a superset of JSON), you can also find example of trailing commas in a few arrays in the default json files, which is not allowed in JSON, but is ok in JSON5
 
C-style comments (/* */) are used by HBS in CombatGameConstants.json for camera work, so you can too as long as you ensure these combinations of chars won't be used as value for a key.