Skip to content

Conversation

@rosbit
Copy link

@rosbit rosbit commented Nov 26, 2018

because awk doesn't support literal JSON object, it is very tedious to create an array variable like this:

   a["f1"] = 1
   a["f2"] = 2
   a["f3"] = 3

I added two syntax sugars to write literal JSON object. The changes includes:

  1. add a keyword "var" to indicate the following NAME is an array variable name
  2. add some tokens, they are "true", "false", F_JARRAY, F_JOBJECT
  3. F_JARRAY and J_OBJECT are implemented as built-in functions to wrapper arguments to array values
  4. expand value struct in interp package to support value type "map[string]value"

now we can write literal JSON object in awk like the following:

  var a = {
       f1: 1, f2: 2, f3:3,
       "a": true, "b": [1, 3, 4]
  }

and we can refer the variable by index like
print a["f1"]

If you think this is useful, merge it to the master trunk. Thank you!

Rosbit Xu.

@benhoyt
Copy link
Owner

benhoyt commented Nov 26, 2018

Hi @rosbit, this is a nice idea. However, I'd like to keep GoAWK close to awk and the POSIX AWK spec, and not add arbitrary features beyond that, so unfortunately I won't be including this.

@benhoyt benhoyt closed this Nov 26, 2018
@ghost ghost mentioned this pull request May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants