项目作者: marcanalella

项目描述 :
Filter your JSON by key value
高级语言: Java
项目地址: git://github.com/marcanalella/filter-json.git
创建时间: 2020-09-20T08:42:07Z
项目社区:https://github.com/marcanalella/filter-json

开源协议:MIT License

下载


Filter JSON

Filter your JSON by key value!

This software provides a filter of an entity’s data in a response to an API request.

By default, services may return some informations that your application doesn’t need. In these cases, you’ll need to use a projection to retrieve only necessary fields.

All the filtering process takes place recursively and it works for both JSON Object and JSON Array.

This software has been structured as indipendent microservice with a REST API

How it works

Application expose /api/v1/getJson API to retrieve filtered JSON. Field projections have to be defined using the query param ?values= with values followed by comma.

If the data is nested, add a dot to the desired value to be filtered.

Finally, to make possible the filtering process, application need all JSON Body in a POST request.

Example with a JSON Object request

To retrieve id and foo fields, this POST call

POST https:/localhost:8080/api/v1/getJson?values=id,foo

  1. {
  2. "id" : int,
  3. "foo": string,
  4. "bar": boolean,
  5. "baz": Object
  6. }

provides the following response:

  1. {
  2. "id": int,
  3. "foo": string
  4. }

Example with a JSON Array request

To retrieve id and foo values inside JSON Array, this POST call

POST https:/localhost:8080/api/v1/getJson?values=id,list.foo

  1. [
  2. {
  3. "id": 2,
  4. "three": {
  5. "point_1": "point_2",
  6. "point_3": 3.4
  7. },
  8. "list": [
  9. "foo" : 1,
  10. "two" : 2,
  11. "three" : 3
  12. ]
  13. },
  14. {
  15. "id": 2,
  16. "three": {
  17. "point_1": "point_2",
  18. "point_3": 3.4
  19. },
  20. "list": [
  21. "foo" : 1,
  22. "two" : 2,
  23. "three" : 3
  24. ]
  25. }
  26. ]

provides the following response:

  1. [
  2. {
  3. "id": 2,
  4. "list": [
  5. "foo" : 1
  6. ]
  7. },
  8. {
  9. "id": 3,
  10. "list": [
  11. "foo" : 1
  12. ]
  13. }
  14. ]