0

The code fails to access JSON object if it's key contain dots.

JSON:

"TableTraps": {    
  "1.3.6.1.4.1.100.108.0.3": {
    "Vars": [ 
      "alarmDescription", 
      "alarmPositionUnit", 
      "alarmChannel"
    ]
  },
  "1.3.6.1.4.1.100.108.0.4": {
    "Vars": [ 
      "alarmDescription", 
      "alarmPositionUnit", 
      "alarmChannel"
    ]
  },
}

Pascal SuperObject code:

TableTraps := LoadFromFile();
TrapOID := '1.3.6.1.4.1.100.108.0.3';
trapInfo := TableTraps.O[TrapOID];

Results in trapInfo == nil but I expect SuperObject instance. I've tried to wrap the json key:

TrapOID := '"' + '1.3.6.1.4.1.100.108.0.3' + '"';

or

TrapOID := '''' + '1.3.6.1.4.1.100.108.0.3' + '''';

It doesn't help.

How should I call SuperObject to access the object instance if the json key contains dots?

Related question How to serialize JSON key containing dots (like e.g. IP address) with SuperObject?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dr.eel
  • 1,837
  • 3
  • 18
  • 28

1 Answers1

1

Related question helped me to find the solution. The suprobject.O called directly on the parsed object parses dots as JSONPath. So instead of accessing "1.3.6.1.4.1.100.108.0.3: {}" it tries to access this JSON:

"1": { "3": { "6": { "1": { "4": { "1": { "100": { "0": { "3": value

Here the workaround:

TableTraps := LoadFromFile();
TrapOID := '1.3.6.1.4.1.100.108.0.3';
trapInfo := TableTraps.AsObject.O[TrapOID]; // NOTE: AsObject is required!
Dr.eel
  • 1,837
  • 3
  • 18
  • 28