Sample code for 30+ languages & platforms
Dart

JSON: Renaming and Deleting Members

See more JSON Examples

Demonstrates renaming and deleting members. This example uses the following JSON document:
{
   "apple": "red",
   "lime": "green",
   "banana": "yellow",
   "broccoli": "green",
   "strawberry": "red"
}

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final json = CkJsonObject();

  try {
    json.load('{"apple": "red","lime": "green","banana": "yellow","broccoli": "green","strawberry": "red"}');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Rename "lime" to "lemon".
  json.rename('lime', 'lemon');
  // Change the color to yellow:
  json.setStringOf('lemon', 'yellow');

  // Rename by index.  Banana is at index 2 (apple is at index 0)
  json.renameAt(2, 'bartlett_pear');

  // Delete broccoli by name
  json.delete('broccoli');

  // Delete apple by index.  Apple is at index 0.
  json.deleteAt(0);

  json.emitCompact = false;
  print(json.emit());
}