Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to store data into a Map from json file #2691

Closed
PrithviDuggirala opened this issue Mar 30, 2021 · 0 comments
Closed

How to store data into a Map from json file #2691

PrithviDuggirala opened this issue Mar 30, 2021 · 0 comments

Comments

@PrithviDuggirala
Copy link

What is the issue you have?

I'm having a json file as follows:

[
{
"top__DOT__comp_ac_Multiplier_Mux01__DOT__H11TW040L_UCVCSND2X010_Z_s": [
"sa0",
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__INDEX02_Outp_s": [
"sa0",
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__comp_H11TW040L_UCVCSND2X010__DOT__NOT00_Outp_s": [
"sa0"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__comp_H11TW040L_UCVCSND2X010__DOT__NOT01_Outp_s": [
"sa0"
]
},
{
"top__DOT__comp_ac_Multiplier_Mux01__DOT__H11TW040L_UCVCSAORI1X010_Z_s": [
"sa0",
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__INDEX00_Outp_s": [
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__INDEX01_Outp_s": [
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__comp_H11TW040L_UCVCSAORI1X010__DOT__BAND_Outp_s": [
"sa0"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__comp_H11TW040L_UCVCSAORI1X010__DOT__NOT_Outp_s": [
"sa0"
]
}
]

It is a list of dictionaries. I want to read this file and store each dictionary into a map of vectors. Later I have to iterate over the each dictionary and extract key and values(which is a list in this case).

I have used the following code to do this:

class faults{

map<string, vector<string>> myMap;

};

std::ifstream myinput("fault_list.json");
auto j = json::parse(myinput);
std::vector fault = j;

I'm facing the following error:
error: conversion from 'nlohmann::basic_json<>' to non-scalar type 'std::vector' requested
std::vector fault = j;
^

Operating System: Unix
Compiler: g++ (GCC) 8.2.0

I used the json.hpp file from here
https://github.com/nlohmann/json/releases/tag/v3.9.1

Kindly help me with the issue.

Repository owner locked and limited conversation to collaborators Mar 30, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants