humps 1.0.1 copy "humps: ^1.0.1" to clipboard
humps: ^1.0.1 copied to clipboard

A Dart package for converting map keys between camelCase and snake_case. Useful for converting between JSON and Dart field names.

humps #

A Dart package for converting map keys between camelCase and snake_case. Useful for converting between JSON and Dart field names.

Features #

  • toCamelCase() method to convert map keys from snake_case to camelCase
  • toSnakeCase() method to convert map keys from camelCase to snake_case
  • Works recursively on nested maps
  • Handles preserving leading underscores

Usage #

Convert a JSON map with snake_case keys to a Dart map with camelCase keys:

final map = {
  '_id': 'value',
  'some_key': 'value',
  'nested_key': {
    'another_key': 'value',
    'nested_key': {'another_key': 'value'},
  },
};
// Woulf became:
final map = {
  '_id': 'value',
  'someKey': 'value',
  'nestedKey': {
    'anotherKey': 'value',
    'nestedKey': {'anotherKey': 'value'},
  },
};

Convert back to snake_case for sending back to a JSON API:

final map = {
  '_id': 'value',
  'someKey': 'value',
  'nestedKey': {
    'anotherKey': 'value',
    'nestedKey': {'anotherKey': 'value'},
  },
};

// Would become:

final map = {
  '_id': 'value',
  'some_key': 'value',
  'nested_key': {
    'another_key': 'value',
    'nested_key': {'another_key': 'value'},
  },
};
4
likes
0
points
43
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for converting map keys between camelCase and snake_case. Useful for converting between JSON and Dart field names.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on humps