Skip to main content

robotframework-jsonlib is a Robot Framework test library for manipulating JSON Object. You can manipulate your JSON object using JSONPath

Project description

robotframework-jsonlib

JSONLib is a Robot Framework test library for manipulating JSON Object. You can manipulate your JSON object using JSONPath

JSONPath is an expression which can help to access to your JSON document. The JSONPath structure is in the same way as XPath which use for accessing XML document. This is an example of JSONPath syntax.

JSONPath Description
$ the root object/element
@ the current object/element
. or [] child operator
.. recursive descent. JSONPath borrows this syntax from E4X
* wildcard. All objects/element regardless their names.
[] subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator.
[,] Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.
[start: end: step] array slice operator borrowed from ES4
?() applies a filter (script) expression.
() script expression, using the underlying script engine.

This library can help you to add, get, update and delete your JSON object. So it's very useful in case that you have a very large JSON object.

Features

  • ✅ Load JSON from files or strings
  • ✅ Query JSON using JSONPath expressions
  • ✅ Update values in JSON objects
  • ✅ Add new objects to JSON
  • ✅ Delete objects from JSON
  • ✅ Validate JSON against schemas
  • ✅ Convert between JSON objects and strings
  • ✅ Pretty-print JSON with custom indentation
  • ✅ Support for complex nested JSON structures

Notes

Please note this library is a bridge between the Robot Framework and the parser jsonpath-ng. Hence, issues related to parsing should be raised on https://github.com/h2non/jsonpath-ng

Starting with version 0.4, Python2 support is dropped as Python2 reached end of life on 1st of January 2020.

Installation

Install robotframework-jsonlib via pip:

pip install -U robotframework-jsonlib

Example Test Case

*** Settings ***
Library JSONLib
*** Test Cases ***
${json_obj}= Load Json From File example.json
${object_to_add}= Create Dictionary country=Thailand
${json_obj}= Add Object To Json ${json_obj} $..address ${object_to_add}
${value}= Get Value From Json ${json_obj} $..country
Should Be Equal As Strings ${value[0]} Thailand
${value_to_update}= Set Variable Japan
${json_obj}= Update Value To Json ${json_obj} $..country ${value_to_update}
Should Be Equal As Strings ${json_obj['country'] ${value_to_update}
Should Have Value In Json ${json_obj} $..isMarried
Should Not Have Value In Json ${json_obj} $..hasSiblings
Dump Json To File ${OUTPUT_DIR}${/}output.json ${json}
${schema_json_obj}= Load Json From File schema.json
Validate Json By Schema ${json_obj} ${schema_json_obj}
Validate Json By Schema File ${json_obj} schema.json

Documentation

Contributing

Contributions are welcome! Please see DEVELOPMENT.md for:

  • Setting up your development environment
  • Running tests and CI checks
  • Building and publishing the package
  • Coding standards and guidelines

Help & Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework_jsonlib-1.0.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

robotframework_jsonlib-1.0.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file robotframework_jsonlib-1.0.0.tar.gz.

File metadata

  • Download URL: robotframework_jsonlib-1.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for robotframework_jsonlib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aae497141148547905b2cf84ad1b709db22978acc47439161b9862f89e610f11
MD5 f5bb2ffbfdba2b8674c41573c2836ed8
BLAKE2b-256 0329f7718851cc76941029d036c50002fee76170487c9a67c7570a4cd8bd4440

See more details on using hashes here.

File details

Details for the file robotframework_jsonlib-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_jsonlib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac470e98d532dae626cb2fd89a9a32dbf76073302066817c61550592fa9af672
MD5 9495c2f08e3c837a0c0889e3045be417
BLAKE2b-256 5b244d0b961e37207d20a9889b52376debbdf399276ff2287c0d0b6c76df8b4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page