Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Append JSON (from hashref)

by Corion (Patriarch)
on Apr 06, 2017 at 11:39 UTC ( [id://1187261]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Append JSON (from hashref)
in thread Append JSON (from hashref)

Yes.

See perldsc on how to manipulate Perl data structures.

You could either add your entry to the result directly, in your Perl code:

$tmp->[0]->{ 'inputPhrase' } = $SearchWord;

... or simply select the search phrase as another column:

SELECT RECNO, DESCRIPTION, ? as inputPhrase FROM RECORDS_TABLE WHERE RECNO LIKE ?
... $sth->execute( $SearchWord, $recno ); ...

Replies are listed 'Best First'.
Re^4: Append JSON (from hashref)
by Anonymous Monk on Apr 06, 2017 at 13:29 UTC
    Thanks, but this first solution means inputPhrase is added in with the details of the first result
    [{"DESCRIPTION":"Description of record","RECNO":"RECORDNumber", "input +Phrase":"RECORDNumber}, ... more records here
    and not outside of the list of results like in the json linked above (won't let me post with the URL here)

      Ah, if you want a different structure, just create that structure.

      Consider writing your data structure in Perl - Perl looks very much like JSON, except that : is spelled => in Perl.

        Can you give some advice on preping this in perl, so far my attempt is failing to produce a structure required:
        while (my $row = $sth->fetchrow_hashref) { print "doc_no: $row->{RECNO} DESCRIPTION: $row->{DESCRIPTION}\n"; $hash{$int} = '"RECNO": "' . $row->{RECNO} . '","DESCRIPTION": "' . +$row->{DESCRIPTION} .'"'; $int ++; } # figure out how to add inputPhrase later.
        Is there a structure I can use which means I don't have to have the $int part?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1187261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found