You could try to write code (perhaps, a single regexp) which will prepend prefix to all keys in JSON string
{ "1_op": "add", "2_path": "/baz", "3_value": "qux", "4_op": "remove" + }

You don't even have to check if this string is a key (it's ok to damage values)
next, parse with JSON module, and when you find "1_op" and "4_op" in same hash - that would mean error.
UPD:
Alpha version:
use strict; use warnings; use JSON::XS; use Data::Dumper; my $s = <<"END"; [ { "op": "add", "path": "/baz", "value": "qux", "op": "remove" } ] END my $x = 1; $s =~ s/\"([^\"]+)\"/"\"".++$x."_".$1."\""/ge; my $j = JSON::XS->new()->filter_json_object(sub { my %seen; for (keys %{shift()}) { die unless /^\d+\_(.*)$/; die "key [$1] already seen" if $seen{$1}++; } }); $j->decode($s);
prints
key [op] already seen
UPD2:
You can even avoid double-parsing, just remove prepended numbers in filter_json_object and return correct data. In the end yo'll get correct hash on first pass.

In reply to Re: make duplicate JSON keys an error by vsespb
in thread make duplicate JSON keys an error by daxim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.