Skip to content
zolfagharisoroush edited this page Mar 12, 2022 · 10 revisions

Getting started

JSON parser is used to parse basiscore's JSON objects into a python's, list of dictionaries which helps developers access data easily.

Import Parser from bclib

 from bclib import parser

Creat your object:

 my_object = parser.ParseAnswer(json_object)

There is another input you can pass to the parse in the first place.(Which it's an optional input)

my_object = parser.ParseAnswer(json_object, restful_context)

The restful context is a basiscore API. Passing this argument to the parser, makes an object (list of dictionaries) that contains prpIds, part numbers, viewtypes, and datatypes and also fills the datatype value in parser output by itself. It helps basiscore developers to edit schemas much easier.

Now parser is ready to use, let's check some examples. You can copy the examples and print them on your machine:

Get all data

This command converts an object into a list of dictionaries. New dictionaries are flattened.

my_object.get_actions()

prpId

prpId is a basiscore key inside the object. Developers can access each dictionaries using this key:

 my_object.get_actions(prp_id=12345)

prpId can also pass to the Parser as a list of integers:

 my_object.get_actions(prp_id=[12345, 1000])

Actions

User actions are EDITED, DELETEd, and ADDED. Here is an example:

 my_object.get_actions(action=(parser.UserActionTypes.EDITED)

Actions can also pass to the Parser as a list:

 my_object.get_actions(action=[parser.UserActionTypes.DELETED, parser.UserActionTypes.ADDED]

Multiple inputs

Get data using prpId and user's actions:

 my_object.get_actions(prp_id=12344, action=parser.UserActionTypes.EDITED)

using lists:

   my_object.get_actions(prp_id=[12344, 1000], action=parser.UserActionTypes.EDITED)

or

 my_object.get_actions(prp_id=1007, action=[parser.UserActionTypes.EDITED, parser.UserActionTypes.DELETED])

and both prpId and action are list:

 my_object.get_actions(prp_id=[1007, 1000] action=[parser.UserActionTypes.EDITED, parser.UserActionTypes.DELETED])

Parts

There is a third parameter, part which is the last parameter in the Parser. Part can be an integer or a list of integers. Here are some examples:

 my_object.get_actions(prp_id=[12345, 1000], part=1)
 my_object.get_actions(prp_id=[1007, 1000] action=[parser.UserActionTypes.EDITED, parser.UserActionTypes.DELETED], part=1)
 my_object.get_actions(action=[parser.UserActionTypes.EDITED, parser.UserActionTypes.ADDED], part=[1, 2]))    

lambda functions

print('f', my_object.get_actions(predicate=lambda x: x.prp_id == 12345 or x.action == parser.UserActionTypes.DELETED))

Clone this wiki locally