JSON Grammar No Root question

82 views
Skip to first unread message

Zeik

unread,
Nov 10, 2024, 5:12:11 PM11/10/24
to Bots Open Source EDI Translator
Hi All,

I have been trying to figure out how to have a JSON grammar with no root as allowed by the JSON standard, is this possible?  Is that what jsonnocheck is for?

Example
     "name": "Jack", 
     "age": 99
 }

Thanks

Wassily

unread,
Nov 11, 2024, 10:48:35 AM11/11/24
to Bots Open Source EDI Translator
Hi Zeik

I am doing this in different places - either in communication scripts or in envelope. But the process is the same:

1. check the grammar and get the element name of the root element
2. read the data and use only the subset of the named element

Something along the line of:
from bots import grammar

def main(channeldict, filename, ta):
  # Get Grammar to remove the 'root' element when sending.
  ta.synall()
  botsgrammar = grammar.grammarread(ta.editype, ta.messagetype, 'grammars')
  rootid = botsgrammar.structure[0][0]

  # Open the file and read json to dict. Later on, dict is sent back to JSON without root.
  infile = open(filename)
  data = json.loads(infile.read())
  data = data[rootid]

Zeik

unread,
Dec 7, 2024, 8:23:20 PM12/7/24
to Bots Open Source EDI Translator
Thanks Wassily, will look into using this.

Zeik

unread,
Dec 8, 2024, 2:07:43 AM12/8/24
to Bots Open Source EDI Translator
Hi Wassily,

I am not as familiar with using the communicationscripts, I have a channel that is part of a composite route.  The composite route has 2 parts, 1st is the translation and then second is just the output to a folder a passthrough.  Should I attach this script to the second channel which is just the output or is there a way to intercept the file from part 1 of the composite script before it goes to part 2 to run this script (I was thinking maybe a routescript using like postmerge?)  or do I just have the script write to the folder myself since main overrides the channel?  I seem to be misunderstanding how to implement the postprocessing correctly, as I do not understand how to write the file back into bots chain of processing.

Thanks

Zeik

unread,
Dec 8, 2024, 2:34:14 AM12/8/24
to Bots Open Source EDI Translator
Made some progress, forgot to set the channel to type: communicationscript (it was previously set to file).  I was able to get it to run but I am unclear on how to put the file back into the process chain to that it outputs to the filepath set in the channel? 

Zeik

unread,
Dec 8, 2024, 1:48:16 PM12/8/24
to Bots Open Source EDI Translator
I was looking at the routescript examples and wondering if this is the way to push the changed file back into the process chain in the code example Wassily posted ? 

ta_to = ta_from.copyta(status=endstatus) #make new transaction for bots database
ta_to.update(statust=OK,filename=ta_from.filename) #update outmessage transaction (same) filename
Reply all
Reply to author
Forward
0 new messages