Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Verbiage in Serialize Command #35

Open
rydtran opened this issue Jul 28, 2022 · 0 comments
Open

Reduce Verbiage in Serialize Command #35

rydtran opened this issue Jul 28, 2022 · 0 comments

Comments

@rydtran
Copy link

rydtran commented Jul 28, 2022

The current serialize command can become verbose when converting a large serialized JSON string with nested subtrees into a JSON file. I propose adding an additional syntax to reduce the verbiage. Or even introduce a new command called deserialize that will convert a serialized tree into a JSON file.

Proposal:
  A new syntax added to serialize.
    or
  A new command called deserialize. I'm more inclined to this option since the name accurately describes the proposed behavior.

We will use the following JSON to demonstrate the differences;

{
  "people" : {
    "ryan" : {
      "age" : 23,
      "hobbies" : {
        "soccer" : "good",
        "running" : "bad"
      },
      "status" : "insomina"
    },
    "john" : {
      "age" : 45,
      "hobbies" : {
        "soccer" : "bad",
        "running" : "good"
      },
      "status": "sad"
    }
  }
}

Old Syntax:

spellbook serialize --output myfile.json --vars \
people/ryan/age=23 \
people/ryan/hobbies/soccer=good \
people/ryan/hobbies/running=bad \
people/ryan/status=insomania \
people/john/age=45 \
people/john/hobbies/soccer=bad \
people/john/hobbies/running=good \
people/john/status=sad\

New Syntax:

spellbook deserialize --output myfile.json \
people>\
ryan>age=23&hobbies>soccer=good&running=bad<status=insomania<\
john>age=45&hobbies>soccer=bad&running=good&status=sad\

Breaking Down the Syntax:

  • ">" tells the program that the next value to read is a child node.
  • "<" tells the program to return to the parent node.
  • "&" tells the program that the next value to read is a sibling node.

Things to Note:

  • After specifying "hobbies" and its child nodes, a "<" symbol is appended. The first instinct is to append "&," but a "<" symbol is needed to tell the program to return to the parent node of "hobbies." This will correctly place "status" as a sibling of "age" and "hobbies."
  • The optional variable "--vars" is not needed since the serialized tree is one continuous string with no spaces.
@rydtran rydtran changed the title Improve Serialization Syntax Reduce Verbiage in Serialize Command Jul 28, 2022
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

No branches or pull requests

1 participant