Use a jQuery Query Builder JSON to evaluate the context.

@param string $json
@param array  $context an array of data to be evaluated

@return bool return true if the context passes the filters of $json

@throws Exception
@throws \Exception
173568
public function filter($json, array $context = [])
    {
        $query = $this->decodeJSON($json);
        if (!isset($query->rules) || !is_array($query->rules) || count($query->rules) < 1) {
            $this->setError('No rules to evaluate.');

            return false;
        }

        return $this->loopThroughRules($query->rules, $context, isset($query->condition) ? $query->condition : 'AND');
    }
793802
public static ReadContext fromJson(String json) {
        Objects.requireNonNull(json, Required.JSON.toString());
        
        return JsonPath.parse(json);
    }
495063
public static boolean isValid(final String json) {
        if (Strings.isEmpty(json)) {
            return false;
        }

        try {
            return parse(json) != null;
        } catch (ParseException e) {
            return false;
        }
    }
884986
private function parseJson($json)
    {
        $jsonPayload = json_decode($json, true);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new ParserException('Error parsing JSON: '
                . json_last_error_msg());
        }

        return $jsonPayload;
    }
383804
protected function response($json)
    {
        if ($json instanceof PaginatedResource) {
            $json = json_encode($json);
        }

        return (new HttpFoundationFactory())->createResponse($this->addHeaders(new Response($json)));
    }
172169
def json_exception(context, request):
    """"""
    request.response.status = context.code
    return {'error': context._status, 'messages': context.message}
1369854
protected function applyBody(&$contextParams, $methodName, $body, $json = true)
    {
        // request body
        if ($methodName == 'POST' || $methodName == 'PUT') {

            $body = (array)$body;

            if($json){
                $content = @json_encode($body);
                if(!$content){
                    throw new \Exception('Body is not serializable');
                }
            }else{
                $content = http_build_query($body);
            }

            $contextParams['http']['content'] = $content;

            $logger = $this->getLogger();
            $logger->debug('Document body: '.var_export($body, true));
            $logger->debug('Document body (JSON-ified): '.$content);
        }
    }
1256012
private function get_json_for_post_request($body, $contextid, $typeid) {
        global $CFG, $DB;

        $json = json_decode($body);
        if (empty($json) ||
                !isset($json->scoreMaximum) ||
                !isset($json->label)) {
            throw new \Exception(null, 400);
        }
        if (is_numeric($json->scoreMaximum)) {
            $max = $json->scoreMaximum;
        } else {
            throw new \Exception(null, 400);
        }
        require_once($CFG->libdir.'/gradelib.php');
        $resourceid = (isset($json->resourceId)) ? $json->resourceId : '';
        $ltilinkid = (isset($json->ltiLinkId)) ? $json->ltiLinkId : null;
        if ($ltilinkid != null) {
            if (is_null($typeid)) {
                if (!gradebookservices::check_lti_id($ltilinkid, $contextid, $this->get_service()->get_tool_proxy()->id)) {
                    throw new \Exception(null, 403);
                }
            } else {
                if (!gradebookservices::check_lti_1x_id($ltilinkid, $contextid, $typeid)) {
                    throw new \Exception(null, 403);
                }
            }
        }
        $tag = (isset($json->tag)) ? $json->tag : '';
        if (is_null($typeid)) {
            $toolproxyid = $this->get_service()->get_tool_proxy()->id;
            $baseurl = null;
        } else {
            $toolproxyid = null;
            $baseurl = lti_get_type_type_config($typeid)->lti_toolurl;
        }
        $params = array();
        $params['itemname'] = $json->label;
        $params['gradetype'] = GRADE_TYPE_VALUE;
        $params['grademax']  = $max;
        $params['grademin']  = 0;
        $item = new \grade_item(array('id' => 0, 'courseid' => $contextid));
        \grade_item::set_properties($item, $params);
        $item->itemtype = 'manual';
        $item->idnumber = $resourceid;
        $item->grademax = $max;
        $id = $item->insert('mod/ltiservice_gradebookservices');
        $DB->insert_record('ltiservice_gradebookservices', (object)array(
                'gradeitemid' => $id,
                'courseid' => $contextid,
                'toolproxyid' => $toolproxyid,
                'typeid' => $typeid,
                'baseurl' => $baseurl,
                'ltilinkid' => $ltilinkid,
                'tag' => $tag
        ));
        if (is_null($typeid)) {
            $json->id = parent::get_endpoint() . "/{$id}/lineitem";
        } else {
            $json->id = parent::get_endpoint() . "/{$id}/lineitem?type_id={$typeid}";
        }
        return json_encode($json, JSON_UNESCAPED_SLASHES);

    }
1185232
public function parseJson($json)
    {
        $this->mentionName = $json['mention_name'];
        $this->id = $json['id'];
        $this->name = $json['name'];
        if (isset($json['links'])) {
            $this->links = $json['links'];
        }
        if(isset($json['xmpp_jid'])) {
            $this->xmppJid = $json['xmpp_jid'];
            $this->deleted = $json['is_deleted'];
            $this->lastActive = $json['last_active'];
            $this->title = $json['title'];
            $this->created = new \Datetime($json['created']);
            $this->groupAdmin = $json['is_group_admin'];
            $this->timezone = $json['timezone'];
            $this->guest = $json['is_guest'];
            $this->email = $json['email'];
            $this->photoUrl = $json['photo_url'];
        }
    }
635584
public function getJsonArray($json)
    {
        $response = $this->sendJsonLoad($json);
        $result = json_decode($response, true);
        if (!$result && !is_null($this->logger)) {
            $this->logger->error("json decode failed for " . substr($response, 0, 100) . " that resulted from " . substr($json, 0, 100));
        }
        return $result;
    }
1016989
public function parse($json, Builder $querybuilder)
    {
        // do a JSON decode (throws exceptions if there is a JSON error...)
        $query = $this->decodeJSON($json);

        // This can happen if the querybuilder had no rules...
        if (!isset($query->rules) || !is_array($query->rules)) {
            return $querybuilder;
        }

        // This shouldn't ever cause an issue, but may as well not go through the rules.
        if (count($query->rules) < 1) {
            return $querybuilder;
        }

        return $this->loopThroughRules($query->rules, $querybuilder, $query->condition);
    }
843780
protected function reverseJsonInContext(array &$context)
  {
    if (!$context) {
      return;
    }

    foreach ($context as $key => $val) {
      if (!$val || !is_string($val) || !($val[0] == '{' || $val[0] == '[')) {
        continue;
      }

      $json = @json_decode($val);
      if (is_object($json) || is_array($json)) {
        $context[$key] = $json;
      }
    }
  }
555189
public function jsonLDSerialize(string $context = self::DEFAULT_CONTEXT, bool $types = null)
    {
        $set = array_map(function ($m) use ($types) {
            return is_object($m) ? $m->jsonLDSerialize('', $types) : $m;
        }, $this->members);

        if (!$this->closed) {
            $set[] = null;
        }
        return $set;
    }
117944
public function decode($json)
    {
        $data = json_decode($json, true);
        if ($data === null && json_last_error() != JSON_ERROR_NONE) {
            throw new JsonSerializerException('Invalid JSON to unserialize.');
        }

        if (!is_array($data)) {
            throw new JsonSerializerException('Given JSON cannot represent an object.');
        }

        if (mb_strpos($json, $this->encodingAnnotation) !== false) {
            $data = $this->decodeNonUtf8FromUtf8($data);
        }

        return $data;
    }
409179
protected function parseJson($type, \SimpleXMLElement $json)
    {
        if (!isset($json->$type)) {
            return false;
        }
        foreach ($json->$type as $url) {
            $this->addArray($type, (array)$url);
        }
        return true;
    }
596407
public function withJsonBody($data, SerializationContext $context = null)
    {
        if (is_string($data)) {
            $json = $data;
        } else {
            $json = SerializerBuilder::create()->build()->serialize($data, 'json', $context);
        }
        $this->withBody($json);

        return $this;
    }
136380
public static function fromJSON( $json, $compiledFolder = null )
	{
		$store = json_decode( $json, true );

		if ( json_last_error() !== JSON_ERROR_NONE )
		{
			$error = XBRL::json_last_error_msg();
			XBRL_Log::getInstance()->err( "$error" );
			return false;
		}

		// Check to see if there is a valid base taxonomy reference $store
		// If there is, this is an extension taxonomy so load it as one.
		if ( isset( $store['baseTaxonomy'] ) && $store['baseTaxonomy'] )
		{
			return XBRL::fromExtensionTaxonomy( $store, $compiledFolder );
		}

		$context = XBRL_Global::getInstance();

		$context->labels				 =& $store['context']['labels'];
		$context->labelLinkRoleRefs		 =& $store['context']['labelLinkRoleRefs'];
		$context->labelRoleRefs			 =& $store['context']['labelRoleRefs'];

		if ( ! empty( $store['context']['calculationRoleRefs'] ) )
		{
			$context->calculationRoleRefs	 =& $store['context']['calculationRoleRefs'];
		}
		if ( ! empty( $store['context']['generalSpecialRoleRefs'] ) )
		{
			$context->generalSpecialRoleRefs =& $store['context']['generalSpecialRoleRefs'];
		}
		if ( ! empty( $store['context']['presentationRoleRefs'] ) )
		{
			$context->presentationRoleRefs	 =& $store['context']['presentationRoleRefs'];
		}
		if ( ! empty( $store['context']['essenceAlias'] ) )
		{
			$context->essenceAlias			 =& $store['context']['essenceAlias'];
		}
		if ( ! empty( $store['context']['requireElements'] ) )
		{
			$context->requireElements		 =& $store['context']['requireElements'];
		}
		if ( ! empty( $store['context']['nonDimensionalRoleRefs'] ) )
		{
			$context->nonDimensionalRoleRefs =& $store['context']['nonDimensionalRoleRefs'];
		}
		if ( ! empty( $store['context']['primaryItems'] ) )
		{
			$context->setPrimaryItemsCache( $store['context']['primaryItems'] );
		}
		if ( ! empty( $store['context']['dimensionDefaults'] ) )
		{
			$context->dimensionDefaults =& $store['context']['dimensionDefaults'];
		}
		if ( ! empty( $store['context']['formulaNames'] ) )
		{
			$context->formulaNames =& $store['context']['formulaNames'];
		}
		if ( ! empty( $store['validTaxonomySet'] ) )
		{
			$context->validTaxonomySet = $store['validTaxonomySet'];
		}
		if ( ! empty( $store['isExtensionTaxonomy'] ) )
		{
			if ( filter_var( $store['isExtensionTaxonomy'], FILTER_VALIDATE_BOOLEAN ) )
			{
				$context->setIsExtensionTaxonomy();
			}
		}

		$instance = null;

		foreach ( $store['schemas'] as $namespace => $data )
		{
			$classname = XBRL::class_from_namespace( $namespace );

			/**
			 * @var XBRL $xbrl
			 */
			$xbrl = new $classname();
			$xbrl->context =& $context;
			$xbrl->fromStore( $data );
			$xbrl->context->importedSchemas[ $namespace ] = $xbrl;
			$xbrl->context->schemaFileToNamespace[ $xbrl->getSchemaLocation() ] = $namespace;
			$xbrl->context->schemaFileToNamespace[ $xbrl->getTaxonomyXSD() ] = $namespace;

			if ( $namespace === $store['mainNamespace'] ) $instance = $xbrl;
		}

		XBRL::fixupForeignDefinitionsFromStore( $store['schemas'] );

		if ( isset( $store['context']['types'] ) )
		{
			// $context->types->fromArray( $store['context']['types'] );
			$context->types->mergeTypes( $store['context']['types'] );
		}

		return $instance;
	}