Check the below code. I used the JSON module, but it gave me error on decoding the string provided by you. Instead of ID value ObjectId("52dfd2750cf2169251fe8d3c"), it's "ObjectId(52dfd2750cf2169251fe8d3c)" that worked with JSON module. I don't know whether you have mentioned the correct json string or not.

use JSON qw(decode_json); my $jsonString = '{ "_id" : "ObjectId(52dfd2750cf2169251fe8d3c)", "closed_on": "ISODate(2014-01-30T18:30:00Z)", "companies": [ { "_id": "ObjectId(52dfd2750cf2169251fe8d3f)", "comp_name": "Test1" }, { "_id": "ObjectId(52dfd7950cf2169251fe8d47)", "comp_name": "Test2" } ], "contacts" : [ { "_id": "ObjectId(52dfd2750cf2169251fe8d3e)", "fname": "Solve", "lname": "Scottt", "email": "email1@gmail.com", "company": "Test111" }, { "_id": "ObjectId(52dfd7950cf2169251fe8d46)", "fname": "signe", "lname": "towne", "email": "email2@gmail.com", "company": "Test222" } ], "crt_by": "creator@gmail.com", "currency": "USD", "type": "None" }'; my $decodedJSON = decode_json($jsonString); print "crts_by = $decodedJSON->{'crt_by'}\n"; print "Contact 1 => fname = $decodedJSON->{'contacts'}[0]{'fname'}, co +mpany = $decodedJSON->{'contacts'}[0]{'company'}\n";

In reply to Re: Need help with $slice MongoDB by simmisam
in thread Need help with $slice MongoDB by vinaybond

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.