/rbkcli/jsonfy
Methods
get
Description: Loads a json file or string, return json result which allows customization.
Parameters: As a parameter you have to pass a single string, being either formatted as natural key assignment or as json string. If the key passed is "file", then instead of loading the string jsonfy will attempt to load the json file. Following is the description of the parameters:
'parameters': [ { 'name': 'file', 'description': 'Path to the json file to be loaded.', 'in': 'body', 'required': True, 'type': 'string' }, { 'name': '<any_keys>', 'description': 'Enter any key as natural key assignment or string Json.', 'in': 'body', 'required': True, 'type': 'string' } ],
Response: The response will vary according to the entered json data.
Usage: It is used to take advantage of the filtering and tabling features of rbkcli with json outputs which are not generated by rbkcli commands. Also to provide input for advanced usage such as looping APIs and caching long output.
Example 1: You can use the output conversion.
$ rbkcli jsonfy -p file=/tmp/example.json -P glossary: title: example glossary GlossDiv: title: S GlossList: GlossEntry: ID: SGML SortAs: SGML GlossTerm: Standard Generalized Markup Language Acronym: SGML Abbrev: ISO 8879:1986 GlossDef: para: A meta-markup language, used to create markup languages such as DocBook. GlossSeeAlso: GML XML GlossSee: markup
Example 2: You can use key mapping.
$ rbkcli jsonfy -p file=/tmp/example.json --select ?MAP [glossary] [glossary][GlossDiv] [glossary][GlossDiv][GlossList] [glossary][GlossDiv][GlossList][GlossEntry] [glossary][GlossDiv][GlossList][GlossEntry][Abbrev] [glossary][GlossDiv][GlossList][GlossEntry][Acronym] [glossary][GlossDiv][GlossList][GlossEntry][GlossDef] [glossary][GlossDiv][GlossList][GlossEntry][GlossDef][GlossSeeAlso] [glossary][GlossDiv][GlossList][GlossEntry][GlossDef][para] [glossary][GlossDiv][GlossList][GlossEntry][GlossSee] [glossary][GlossDiv][GlossList][GlossEntry][GlossTerm] [glossary][GlossDiv][GlossList][GlossEntry][ID] [glossary][GlossDiv][GlossList][GlossEntry][SortAs] [glossary][GlossDiv][title] [glossary][title]
Example 3: You can use key selection.
$ rbkcli jsonfy -p file=/tmp/example.json --select [glossary][GlossDiv][GlossList][GlossEntry][GlossDef][GlossSeeAlso] { "glossary_GlossDiv_GlossList_GlossEntry_GlossDef_GlossSeeAlso": [ "GML", "XML" ] }
Example 4: You can also use it by providing the natural key assignment.
$ rbkcli jsonfy -p "id=my long id,name=my name,property=my property" { "id": "my long id", "name": "my name", "property": "my property" }
Example 5: You can assign the content of the file to bash variable and provide the variable as parameter. Obs.: The same can be done to any API that requires a json parameter.
$ example_var=$(cat /tmp/example.json) $ rbkcli jsonfy -p "$example_var" { "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": [ "GML", "XML" ] }, "GlossSee": "markup" } } } } }
[Back to Meta APIs]
Last updated
Was this helpful?