0

Would like ideas for the easiest way to do this to multiple files(example below). I prefer TCL. Can this be done easily with regsub?

Note: Only want keys to change to lowerCamel case, not the values.

"FooBar": [
        {
            "NumOne": "Hello",
            "SecondThing": true,

to

"fooBar": [
        {
            "numOne": "Hello",
            "secondThing": true,
Kenadams
  • 47
  • 1
  • 6

1 Answers1

2

How about:

#!/usr/bin/tclsh

while {! [eof stdin]} {
    gets stdin line
    if [regexp {(^.*")([A-Z])([^"]+"\s*:.+)} $line x a b c] {
        set line [join [list $a [string tolower $b] $c] ""]
    }
    puts $line
}

and say:

./thisscript.tcl < file.json
tshiono
  • 21,248
  • 2
  • 14
  • 22