operator []= method

void operator []=(
  1. dynamic key,
  2. dynamic dNewValue
)

if key is String & type is map set map value if key is int & type is list set list value if key is List<String/int> recursive aboves.

Implementation

void operator []=(dynamic key, dynamic dNewValue) {
  final newValue = JSON(dNewValue);
  if (key is int &&
      _type == Type.list &&
      key < _rawList.length &&
      newValue.error == null) {
    value = _rawList..[key] = newValue.value;
  } else if (key is String && _type == Type.map) {
    if (newValue.error == null) {
      value = _rawMap..[key] = newValue.value;
    } else {
      value = _rawMap..remove(key);
    }
  } else if (key is List) {
    switch (key.length) {
      case 0:
        return;
      case 1:
        this[key[0]] = newValue;
        break;
      default:
        final path = List.from(key);
        path.removeAt(0);
        final nextJSON = this[key[0]];
        nextJSON[path] = newValue;
        this[key[0]] = nextJSON;
    }
  }
}