Coder Social home page Coder Social logo

Comments (4)

norberttech avatar norberttech commented on July 30, 2024 1

Hey, your example does not have a valid JSON, because of that PHPMatcher thinks this is just a regular text.
The following line is not correct from a json point of view.

{
        "aws": {
            "key": "laclédepassepartout",
            "secret": "lesecretdupèrefouras",
-            "@...@"
        }
    }

from php-matcher.

domis86 avatar domis86 commented on July 30, 2024 1

@tentacode can you try like this? :

$expectedJsonMatcher = <<<JSON
    {
        "aws": {
            "key": "laclédepassepartout",
            "secret": "lesecretdupèrefouras",
            "@*@": "@*@"
        }
    }
    JSON;

from php-matcher.

tentacode avatar tentacode commented on July 30, 2024

Hey, it's not the Json, but the Json Pattern, the Json is ok in the variable $actualJson.

It should work when I read the documentation the @...@ should be supported.

https://github.com/coduo/php-matcher#json-matching-with-unbounded-arrays-and-objects

Json matching with unbounded arrays and objects

<?php

use Coduo\PHPMatcher\PHPMatcher;

$matcher = new PHPMatcher();

$matcher->match(
  '{
    "users":[
      {
        "firstName": "Norbert",
        "lastName": "Orzechowicz",
        "created": "2014-01-01",
        "roles":["ROLE_USER", "ROLE_DEVELOPER"],
        "attributes": {
          "isAdmin": false,
          "dateOfBirth": null,
          "hasEmailVerified": true
        },
        "avatar": {
          "url": "http://avatar-image.com/avatar.png"
        }
      },
      {
        "firstName": "Michał",
        "lastName": "Dąbrowski",
        "created": "2014-01-01",
        "roles":["ROLE_USER", "ROLE_DEVELOPER", "ROLE_ADMIN"],
        "attributes": {
          "isAdmin": true,
          "dateOfBirth": null,
          "hasEmailVerified": true
        },
        "avatar": null
      }
    ]
  }',
  '{
    "users":[
      {
        "firstName": "@string@",
        "lastName": "@string@",
        "created": "@[email protected]()",
        "roles": [
            "ROLE_USER",
            "@...@"
        ],
        "attributes": {
          "isAdmin": @boolean@,
          "@*@": "@*@"
        },
        "avatar": "@[email protected]({\"url\":\"@[email protected]()\"})"
      }
      ,
      @...@
    ]
  }'
);

from php-matcher.

norberttech avatar norberttech commented on July 30, 2024

@domis86 is right here, you should use "@*@" if you just want wildcard, @...@ was made for arrays, not properties.

Example

There is also no such thing as "Json Pattern", in order to match value against pattern, json matcher must turn both of them into arrays, it's impossible to achieve that when pattern is not even a JSON.

from php-matcher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.